delphitdatetimesatelliteforms

TDateTime To ShortDateString In Satellite Forms "VB-clone"


I am trying to find a calculation that will convert the TDateTime value 40653.6830593 into a year, a month, a day, an hour, a minute and a second.

I am sure this is possible, of course, but my brain doesn't have the power, it seems, to write a formula that will extract those values from that double.

I am using a Satellite Forms, a vb-like language, but don't expect that I would need any specific .NET libraries to do this, right? It should just be a numeric calculation... right?

Thanks for the help! Most sincerely.

Joe


Solution

  • Legacy VB or VBA (even Excel) would treat a Date as the number of days since 12/30/1899, and I believe the same is true for Delphi. As such, in legacy VB/VBA, you could write

    Dim myDate as Date
    myDate = myDate + 40653.68303593
    

    To get April 20, 2011 4:23:36 PM. In VB.NET, it's different, as the DateTime struct defaults to January 1, 0001.

    Dim myDate As New DateTime(1899, 12, 30)
    myDate = myDate.AddDays(40653.68303593)
    

    Another user has already posted a Delphi answer.

    At any rate, the basic premise is that you're adding the number of days, with the decimal portion representing the time. So in this example, 40653 full days have passed since 12/30/1899, and 0.683... partial days.