san-san
san-san

Reputation: 64

What type of date format is this?

I have a value like this2015-12-18 11:14:20.72+05:30 and i would like to convert it to yyyy/dd/mm format. I would like to know what format is the date I mentioned above.

Thank you

Upvotes: 1

Views: 44

Answers (2)

san-san
san-san

Reputation: 64

It seems that VBA could not directly convert this timestamp. What I did is just to get the first 10 characters and then convert it to Date.

Upvotes: 0

Cindy Meister
Cindy Meister

Reputation: 25663

This appears to be an ISO date with more information than VBA is designed to handle. For example, at the end it appears to have the difference to GMT for the configuration on which it was generated. VBA wasn't designed to work with milliseconds or GMT information - the programming language hasn't been updated for over a decade, except for new objects in the Office applications.

If you cut off the .72+05:30 VBA can work with the rest of the information. For example:

year = DatePart("yyyy", "2015-12-18 11:14:20") 'returns 2015
hour = DatePart("h",  "2015-12-18 11:14:20") 'returns 11

You can trim off the end using string manipulation, for example:

sDateInfo = "2015-12-18 11:14:20.72+05:30"
sDateTrimmed = Left(sDateInfo, Instr(sDateInfo, ".")-1)
sDateFormatted = Format(sDateTrimmed, "yyyy/dd/mm")

Upvotes: 1

Related Questions