ASP - Serial Date - Cdate() - Function
The information and code available on the subject of converting dates to serial or Julian is very limited. After some research and tinkering, I made a Function for my use that simplifies conversions. The code is very flexible and easily modified for other purposes. I'm using it to save dates to a database and then convert them back as needed.
-------------------------
Function cvtDateSerial(D1,V1)
x1=Cdate(D1)
x2=x1-Cdate("1/1/1900")+2
if V1=1 then x2=Clng(x2) 'remove hours,min,sec
cvtDateSerial=x2
End Function
Function cvtSerialDate(D1,V1)
x1=Cdate(D1)
x2=Cdate(Clng(D1)) 'remove hours,min,sec
if V1=0 then cvtSerialDate=x1
if V1=1 then cvtSerialDate=x2
if V1=2 then cvtSerialDate=FormatDateTime(x2,2)
if V1=3 then cvtSerialDate=month(x2) & "/" & day(x2)
if V1=4 then cvtSerialDate=month(x2) & "/" & day(x2) & "/" & right(year(x2),2)
End Function
-------------------------
To run an example, click here.
To download code, click here.
Please let me know if this has helped you.
| Posted by John at 11:03:51 AM in Web Development (13) |
| --- |







