Dates! Dates! Dates!

P

PW

<rant>

Sorry guys, but I just have to whinge. Dates in ASP are a total pain in the
butt! I seem to get caught out so many times. I realise its my own fault,
but going from the posts in this newsgroup and others, I'm not the only one.
Its just a poorly addressed issue within ASP. So for all your poor buggers
out there that are having problems, particularly with european date formats,
here is my solution.

I have the user enter their date in european format ("31-12-2004") and then
handle it this way ...

myDate = Request.QueryString("txtDate")
myArray = Split(myDate, "-")
myDD = myArray(0)
myMM = myArray(1)
myYYYY = myArray(2)
myISOdate = myYYYY & "-" & myMM & "-" & myDD

I find that ISO formatted dates typically go into the database of choice
pretty readily.

Hope this helps someone.

Cheers,
PW

</rant>
 
E

Evertjan.

PW wrote on 07 aug 2004 in microsoft.public.inetserver.asp.general:
I have the user enter their date in european format ("31-12-2004") and
then handle it this way ...

myDate = Request.QueryString("txtDate")
myArray = Split(myDate, "-")
myDD = myArray(0)
myMM = myArray(1)
myYYYY = myArray(2)
myISOdate = myYYYY & "-" & myMM & "-" & myDD

Usually I also allow for YY, the . and the /, so:

function myISOdate(d)
d = trim(d)
d = replace(d,".","-")
d = replace(d,"/","-")
a = Split(d,"-")
if len(a(2))=2 then a(2) = "20" & a(2)
myISOdate = a(2) & "-" & a(1) & "-" & a(0)
end function
 
P

PW

Evertjan. said:
Usually I also allow for YY, the . and the /, so:

function myISOdate(d)
d = trim(d)
d = replace(d,".","-")
d = replace(d,"/","-")
a = Split(d,"-")
if len(a(2))=2 then a(2) = "20" & a(2)
myISOdate = a(2) & "-" & a(1) & "-" & a(0)
end function


Hmmm, thats a good idea, except for if the user enters something like
"20/01/60" in which 60 become 2060 insted of 1960.
But I will incorporate that change, thanks. :)
 
E

Evertjan.

PW wrote on 08 aug 2004 in microsoft.public.inetserver.asp.general:
Hmmm, thats a good idea, except for if the user enters something like
"20/01/60" in which 60 become 2060 insted of 1960.

if you want to define that for say 2009/1910:

if len(a(2))=2 and +a(2)<10 then
a(2) = "20" & a(2)
elseif len(a(2))=2 and +a(2)>=10 then
a(2) = "19" & a(2)
end if
 
M

Mark Schupp

It's really not an "ASP" problem. The same issues come up in any programming
environment where the person entering the dates may use a different format
than the system storing the dates. We finally gave up on manually entered
text dates in our system and now use a popup date calendar that always sends
the dates to the web server as "yyyymmdd hh:mm:ss",
 

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

Forum statistics

Threads
473,734
Messages
2,569,441
Members
44,832
Latest member
GlennSmall

Latest Threads

Top