DateSerial (to and from)

Posted on 2011-04-26
Last Modified: 2012-05-11

I need a function that can convert a string to and from the dateserial format (including partial days - see examples below).


And from (y/m/d h:m:s):

2009/01/01 00:00:01
2010/07/12 17:53:22

The dates are stored in a file so storing them via strings is what is desired if possible.

Thanks in advance for any assistance.
Question by:rite_eh
    LVL 142

    Accepted Solution

    assuming you speak vb not .net:
    dt2 = Format(dec, "yyyy/mm/dd hh:mm:ss")
    LVL 16

    Assisted Solution

    Format converts a date value to a string.
    CDate can convert a string to a date.  However, the string much be a recogizable date.  If the string has extra text that doesn't include date information, then the CDate function throws an error.
    LVL 1

    Author Comment

    What about converting from a standard date (ex. yyyy/mm/dd hh:mm:ss) to the serial date format, how could this be done?
    LVL 1

    Author Comment

    I managed to perform the latter by using CDec(CDate("yyyy/mm/dd hh:mm:ss")) to give me the date/time in the decimal format. Thanks for the assistance.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Introduction While answering a recent question ( in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
    When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
    As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
    Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now