Serial date conversion to semi string data.

  • I need this: 38842.8287152778 to be converted into 05052006_075321PM. This is the date for May 5th 2006 @ 7:53:21 pm in VBA. How do i get there from 38842.8287152778?

  • Re: Serial date conversion to semi string data.


    You can use custom format. Select the whole column. Right click go to format cells then number then select custom and type this in the custom box.


    [COLOR="Navy"]mmddyyyy"_"hhmmss AM/PM[/COLOR]

  • Re: Serial date conversion to semi string data.


    One way using CDate.

    Code
    MsgBox Format(CDate(38842.8287152778), "mmddyyyy_hhmmss AM/PM")
  • Re: Serial date conversion to semi string data.


    You can try this



    you can pass in a cell value and it should do what you want

  • Re: Serial date conversion to semi string data.


    Cdate works easy enough. I had been looking for an easy way to get that done. I am new to VBA, so I haven't seen that debug.print <string> command before. That is pretty cool.

  • Re: Serial date conversion to semi string data.


    It is probably overkill, but if you wanted to use a function with Insomniacs suggestion of CDate() it is simple enough to change my original one;


    Code
    Function ConvertTime(ByRef dtValue As Date) As String
    
    
    If IsDate(dtValue) Then
        ConvertTime = Format$(dtValue, "mmddyyyy_hhmmssAM/PM")
    End If
    
    
    End Function

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!