PDA

View Full Version : Date Format


Abd
06-09-2003, 12:52 PM
Hi All,

how do I convert 6/9/2003 to 06/09/2003 in ASP

Abdul

raf
06-09-2003, 01:24 PM
Probably with

dim date2, date1
date2 = CDate(date1)

where date1 is the form without the 0 and date2 with the 0. But i fear ASP will then consider it as mm/dd/yyyy.
So this sort of stuf is safer

dim date2, date1
date2=CDate(CInt(day(date1)) + "/" + CInt(month(date1)) + "/" + CInt(year(date1)))

(can be used without the CDate)

Abd
06-09-2003, 03:00 PM
Hi raf,

the first option return Date in the m/d/yyyy format while the second option that is;
dim date2, date1 date2=CDate(CInt(day(date1)) + "/" + CInt(month(date1)) + "/" + CInt(year(date1)))


return this ERROR Message;

Error Type:
Microsoft VBScript runtime (0x800A000D)
Type mismatch: '[string: "/"]'


Thanks

Abd

raf
06-09-2003, 03:23 PM
Hmm. Try

dim date2, date1
date2=day(date1)) & "/" & month(date1)) & "/" & year(date1)
date2=CDate(date2)

i don't know. Never had anything like that. How did you get the original value?

Abd
06-09-2003, 03:56 PM
original value,.......... do you mean date1


I used

<%
date1 = date()

%>

Abd
06-09-2003, 04:03 PM
yeah raf,

came out but in this form 9/6/2003 ,

what I want is 09/06/2003, I want (0) before day and month.

Abd

raf
06-09-2003, 05:53 PM
I see what you want, but you should start from the date. Like
date2=day(date()) & "/" & month(date()) & "/" & year(date())

i used that and it always worked. If you just want to display the date in the dd/mm/yyyy format of your regional settings, then use
session.LCID =your landcode ID

petertran123
06-17-2003, 03:23 PM
i have a date format 06121974 how do i convert it into 06/12/1974. Can someone help me with this thanks

raf
06-17-2003, 03:33 PM
dim value, datevalue
value="06121974" 'or CStr(yournumericalvariable)
datevalue = CDate(Left(value,2) & "/" & Mid(value,3,2) & "/" & Right(value,4))

maybe for safety

dim value, datevalue
value="06121974" 'or CStr(yournumericalvariable)
if Len(value) = 8 then
datevalue = CDate(Left(value,2) & "/" & Mid(value,3,2) & "/" & Right(value,4))
else
response.write("Problem")
end if