Date with zeros

J

James Baker

Aside from rolling my own solution (obviously not very difficult), is there
any way to cause a date such as 6/5/2004 to show up as 06/05/2004? Just
didn't know if there was an ASP function to do this or not.

Thanks,
James
 
E

Evertjan.

James Baker wrote on 16 jun 2004 in
microsoft.public.inetserver.asp.general:
Aside from rolling my own solution (obviously not very difficult), is
there any way to cause a date such as 6/5/2004 to show up as
06/05/2004? Just didn't know if there was an ASP function to do this
or not.

No, there is no ASP function, as ASP is not a language but a platform
accommodating different languages serverside.

6/5/2004 could mean two different dates, btw.

==================================

//Javascript solution:

var d = "6/5/2004"

function two(x){
return (x<10)?"0"+x:""+x
}

d = d.split("/")

d[0] = two(d[0])
d[1] = two(d[1])

d = d.join("/")

====================================

'' vbscript solution

d = "6/5/2004"

function two(x)
two = right("0" & x, 2)
end function

d2 = split(d,"/")


d2(0) = two(d2(0))
d2(1) = two(d2(1))

d = join(d2,"/")
 
J

James Baker

Semantics, lol. Yeah, I know the solution is a cakewalk but I figured if
there was a function, why not use it. Thanks none-the-less.

James


Evertjan. said:
James Baker wrote on 16 jun 2004 in
microsoft.public.inetserver.asp.general:
Aside from rolling my own solution (obviously not very difficult), is
there any way to cause a date such as 6/5/2004 to show up as
06/05/2004? Just didn't know if there was an ASP function to do this
or not.

No, there is no ASP function, as ASP is not a language but a platform
accommodating different languages serverside.

6/5/2004 could mean two different dates, btw.

==================================

//Javascript solution:

var d = "6/5/2004"

function two(x){
return (x<10)?"0"+x:""+x
}

d = d.split("/")

d[0] = two(d[0])
d[1] = two(d[1])

d = d.join("/")

====================================

'' vbscript solution

d = "6/5/2004"

function two(x)
two = right("0" & x, 2)
end function

d2 = split(d,"/")


d2(0) = two(d2(0))
d2(1) = two(d2(1))

d = join(d2,"/")
 
B

Bullschmidt

To make a variable be in the format of mm/dd/yyyy (and the final line of
code can be modifed for other date formats), perhaps try something like
the following which you might even make into a function:

varFld = CDate(MyVariable)

intMonth = Month(varFld)
intDay = Day(varFld)
intYr = Year(varFld)

If intMonth < 10 Then
strMonth = "0" & CStr(intMonth)
Else
strMonth = CStr(intMonth)
End If

If intDay < 10 Then
strDay = "0" & CStr(intDay)
Else
strDay = CStr(intDay)
End If

strYr = Right(CStr(intYr), 4) ' And change the 4 to 2 for 2 year dates.

varFld = CStr(strMonth & "/" & strDay & "/" & strYr)

Best regards,
J. Paul Schmidt, Freelance ASP Web Designer
http://www.Bullschmidt.com
ASP Design Tips, ASP Web Database Demo, Free ASP Bar Chart Tool...


*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
 
D

dlbjr

Function FormatDate(dtm1)
FormatDate = "NAD" ' Not A Date
If IsDAte(dtm1) Then
FormatDate = Right("00" & Month(dtm1),2) & "/" & Right("00" & Day(dtm1),2) & "/" &
Year(dtm1)
End If
End Function

'dlbjr

'Unambit from meager knowledge of inane others,engender uncharted sagacity.
 
R

Roland Hall

: Function FormatDate(dtm1)
: FormatDate = "NAD" ' Not A Date
: If IsDAte(dtm1) Then
: FormatDate = Right("00" & Month(dtm1),2) & "/" & Right("00" &
Day(dtm1),2) & "/" &
: Year(dtm1)
: End If
: End Function

you only need one zero there buddy...

--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,156
Messages
2,570,878
Members
47,408
Latest member
AlenaRay88

Latest Threads

Top