Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help With < %= FormatDateTime(Date(),2)% >

Status
Not open for further replies.

DallasAggie

Programmer
Oct 24, 2002
98
US
Hi all,

I am having trouble getting the format I need to display on a page. I have this page, that when opened, it'll insert today's date in a form field and automatically query a database for today's date.

The problem I'm having is that <%= FormatDateTime(Date(),2)%> is giving me m/d/yyyy. I need to display it in 2-digit month, 2 digit-day & 4-digit year..as: mm/dd/yyyy. I've searched all boards and I cannot find a solution.

Since I have the code inside of a text box, I'm not sure of any other way to get around this. Here is a snippet of the code.

</select>
</b></font></td><td width=&quot;15%&quot; align=&quot;center&quot; valign=&quot;top&quot;>
<p align=&quot;center&quot;><font size=&quot;2&quot; face=&quot;Arial, Helvetica, sans-serif&quot;>
<input name=&quot;LastUpdate_Input&quot; type=&quot;text&quot; id=&quot;LastUpdate_Input&quot; size=&quot;15&quot; maxsize=&quot;10&quot; tabindex=&quot;3&quot; value=&quot;<%= FormatDateTime(Date(),2)%>&quot;>
</font></p>
</td>
<td width=&quot;25%&quot; align=&quot;center&quot; valign=&quot;top&quot;><font size=&quot;2&quot; face=&quot;Arial, Helvetica, sans-serif&quot;>
<input name=&quot;name_input&quot; type=&quot;text&quot; size=&quot;20&quot; maxsize=&quot;10&quot; value=&quot;&quot; tabindex=&quot;4&quot;>
</font></td>


Does anyone have any suggestions?

Thanks in advance.
Roberto Andrade, Jr.
Boeing Homeland Security & Services


 
onpnt,

Thanks for the suggestion. I tried using it, but the Date() & Now() functions still return only single digit momth/day. I need the leading zeros in order for my query to work properly....but I did find a solution and thought I would share it with you....and anyone else who is interested.

Step 1: Use the standard VBscript Day(), Month(), and Year() functions to get the day, month and year numbers, so that the conversion will depend from the international settings of the machine or the current LCID of the session.

Step 2: Day() and Month() will restitute a one digit number for days and months less than 10. How can we neatly add a zero in front of the number without using the old If Len(string) < 2 Then ...?

Simple: we will add 100 to the number given by the function. If the function restitutes 2, we will have 102. Next, we will convert 102 into a string with Cstr(102) and we'll have &quot;102&quot;. Finally, to get only the last two digits: Right(&quot;102&quot;,2) gives &quot;02&quot;. That's it, now we have the leading zero.


<%
DIM dteDay, dteMonth, dteYear
dteMonth = Month(now())
dteDay = Day(now())
dteYear = Year(now())
IsoDate = Right(Cstr(dteMonth + 100),2) & _
&quot;/&quot; & Right(Cstr(dteDay + 100),2) & _
&quot;/&quot; & dteYear
%>

----code sample By Giuliano Sauro

Thanks,
Roberto Andrade, Jr.
 
mm = Month(date())
dd = Day(Date())
yyyy = Year(Date())

if dd < 10 then
dd = &quot;0&quot; & dd
end if
if mm < 10 then
mm = &quot;0&quot; & mm
end if
alert mm & &quot;/&quot; & dd & &quot;/&quot; & yyyy


just a thought from the FAQ with a few lines of formatting A language that doesn't affect the way you think about programming is not worth knowing.
admin@onpntwebdesigns.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top