ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   date formatting (https://www.excelbanter.com/excel-programming/285355-date-formatting.html)

douvid

date formatting
 
Hi ,
I got a string like "20030101" and I want this to become the date 01 jan 03 . I can't figure it out. Can you please help if this action is possible

Cheers,
Douvid

J.E. McGimpsey

date formatting
 
One way:

Select your date string(s). Choose Data/Text to Columns. Click Next,
Next. Select YMD in the date dropdown. Click Finish. Format as a
date.


Note: Your example is ambigouous, so you may need to use YDM instead.

In article ,
douvid wrote:

Hi ,
I got a string like "20030101" and I want this to become the date 01 jan 03 .
I can't figure it out. Can you please help if this action is possible


douvid

date formatting
 
ok but I'm want to do all that from vba. through coding

Tom Ogilvy

date formatting
 
Turn on the macro recorder and do it manually. (for Text to columns)

If you are talking about parsing a string (assuming string is yyyymmdd)

Dim dt as Date
Dim sStr as String
sStr = "20030101"
dt = DateValue(Mid(sStr,5,2) & "/" & mid(sStr,7,2) & "/" & Left(sStr,4))

Demo'd from the immediate window:
sStr = "20030101"
? DateValue(Mid(sStr,5,2) & "/" & mid(sStr,7,2) & "/" & Left(sStr,4))
1/1/03

--
Regards,
Tom Ogilvy


douvid wrote in message
...
ok but I'm want to do all that from vba. through coding





All times are GMT +1. The time now is 04:13 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com