Datetime to specific Text Format

Accepted Solution Solved
Reply
Super Contributor
Posts: 418
Accepted Solution

Datetime to specific Text Format

Hello everyone. Is there a format (or combinations of formats) that will display a datetime in the following format?

 

YYYY-MM-DD_HH_MM_SS.

 

For example: 09JUN2015:14:02:00.000  woiuld become 2015-06-09_14_02_00.

 

So far I have the first part 2015-06-09, however can't think of a time one that puts the time as HHMM_SS.   

 

DATENEW=strip(PUT(datepart(DateCompleted), yymmdd10.));

 

Sorry for the easy question, and thanks!


 


Accepted Solutions
Solution
‎06-15-2015 11:47 AM
Super User
Posts: 1,111

Re: Datetime to specific Text Format

Please try

data have;

input date : datetime20.;

format date datetime20.;

cards;

09JUN2015:14:02:00.000

;

data want;

set have;

datetime=catx('_',put(datepart(date),yymmdd10.),tranwrd(put(timepart(date),tod8.),':','_'));

run;

Thanks,

Jag

Thanks,
Jag

View solution in original post


All Replies
Solution
‎06-15-2015 11:47 AM
Super User
Posts: 1,111

Re: Datetime to specific Text Format

Please try

data have;

input date : datetime20.;

format date datetime20.;

cards;

09JUN2015:14:02:00.000

;

data want;

set have;

datetime=catx('_',put(datepart(date),yymmdd10.),tranwrd(put(timepart(date),tod8.),':','_'));

run;

Thanks,

Jag

Thanks,
Jag
Super Contributor
Posts: 418

Re: Datetime to specific Text Format

That worked perfectly, thank you!

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 151 views
  • 0 likes
  • 2 in conversation