'How to convert Datetime from (ddmmyyyy hh:mm:ss) to (ddmmmyyyy:00:00:00) [SAS]

I need to convert hour, minutes and seconds to 00:00:00

I´ve tried a lot but i got nothing but the real time.

data pr; dat=put(date()-1,yymmddn.); datsas=PUT(datetime(), datetime.); run;

Thank You!



Solution 1:[1]

Do you have a datetime value already? If you want to remove the timepart from that datetime value you can just use subtraction.

midnight = datetime - timepart(datetime);

Or you could take the datepart and recreate a datetime value from it.

midnight = dhms(datepart(datetime),0,0,0);

Or you could use INTNX() function to transform to the start of the current DTDAY interval

midnight = intnx('dtday',datetime,0,'b');

Solution 2:[2]

Use the INTNX function to advance a date time value to another date time value.

Example:

data _null_;
  now_dtm = datetime();
  now0_dtm = intnx ('dtday', now_dtm, 0);

  put now_dtm datetime19.;
  put now0_dtm datetime19.;
run;

----- Log -----
 10FEB2022:04:22:51
 10FEB2022:00:00:00

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Tom
Solution 2 Richard