BookmarkSubscribeRSS Feed
SASPhile
Quartz | Level 8

I'm having issues converting iso8601 date to numeric and back to iso8601. When converting back to iso8601, I'm getting extra 00's in the time component.

Ex: 2019-12-01T16:40 gets converted to numeric,.To reconvert it back I'm getting 2019-12-01T16:40:00

ANy help is apprecited.

6 REPLIES 6
SASPhile
Quartz | Level 8

THanks. what if the some dates have seconds like 2019-12-01T16:40:35  and some dont have 2019-12-01T16:40?

 

Kurt_Bremser
Super User

Use the longer format.

2019-12-02T16:40 equals 2019-12-01T16:40:00 anyway, so there's no need to mask the seconds. The shorter format is only useful when seconds don't count.

SASPhile
Quartz | Level 8

If the date doesnt have seconds ,I dont want to display seconds.

 

Kurt_Bremser
Super User

Then you would need to create a custom format with an embedded function that uses the shorter format when there are no seconds (mod(value,60) = 0).

Or if you just need it in a report, conditionally format to a string first.

 

My VERY STRONG advice: don't do it, it's not worth the effort. If somebody complains, use a LART.

Tom
Super User Tom
Super User

@SASPhile wrote:

If the date doesnt have seconds ,I dont want to display seconds.

 


Then you need to store that information in another variable. The easiest way is to just keep the original text string.  Or you could store the length of the original string.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 6 replies
  • 848 views
  • 0 likes
  • 3 in conversation