VBA \ VB6 -
I have a long number: 20141202153026
which should be converted to a date\time (just to be turned back to a properly formatted date string) as:
2014/12/02 15:30:26
Using CDate()
just isn't cutting it.
Format$("20141202153026", "dd/mm/yy hh:mm:ss")
Also seem to fail. Need a direction here.
EDIT: i used jac's solution and it worked great. One thing to remember though is to cast the result back to date with cDate() - to make sure locale settings kick in and arrange the year and the month at their right positions DD/MM/YYYY
CDate(Format$("20141202153026", "####/##/## ##:##:##"))
I have to go with Bond's answer for being more robust, but if you're looking for the fastest least code way out and just because I love alternatives you could format your date time string into a date format then convert that.
'number mask depends on the input being correct
CDate(Format$("20141202153026", "####-##-## ##:##:##"))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With