Quantcast

Friday, December 21, 2007

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.

 

Comments

-- Add Your Comment --

Name
URL
Email
Email address is not published
Remember Me
Comments

CAPTCHA
Write the characters in the image above

Things to Do
John's business web site
  
Google RSS and Gadget

Visit or Join Blog Catalog
Things to Buy

Nice tool to speed up your PC

Look for Pocket Controller Pro
Things to Read
Mezzanine View
Politics - Environment - Technology
Bridging the Gap...
to better writing
Autorotate's Flying Circus
Politics with humor - enjoy
Things to Buy

Best for Windows on Mac

Great backup software - low price
'Who sent you' top 10
Shameless Plugs
VBS Reachout Adventures
Vacation Bible School Program
Keep'n' Safe
Good deals on gun safes
Screw Outfitters
Complete line of Faspac fasteners
Tom Haseltine Photography
Note cards and more
East Point Seafood
Order canned seafood from cannery