scott wrote:
I'm trying to isolate just the m/d/yyyy part of a datetime string like
below. Can someone tell me why my string modification fails on some
dates? I thought byb basing my code on where the blank space between
the date and time would work. my code works on some dates that are
single digit days and months.
mydate = "12/30/2005 10:00 AM"
newDate = Left(mydate,len(mydate)-Instr(mydate," "))
response.write newDate
' trying the return 12/30/2005
Just to add a new wrinkle, and perhaps to make it a little more robust:
mydatestring = "12/30/2005 10:00 AM"
if isdate(mydatestring) then
mydate=cdate(mydatestring)
mydate=dateserial(year(mydate),month(mydate),day(m ydate))
response.write formatdatetime(mydate,2)
else
response.write mydatestring & " is not a valid date<BR>"
end if
To make it even more robust, you should require dates to be supplied in
yyyy-mm-dd format.
Bob Barrows
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.