Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VBA \ VB6 - Convert number to DATE

Tags:

vba

vb6

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", "####/##/## ##:##:##"))
like image 960
Stavm Avatar asked Jul 16 '15 19:07

Stavm


1 Answers

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", "####-##-## ##:##:##"))
like image 145
jac Avatar answered Oct 26 '22 08:10

jac