Obsidian | Level 7

## How to add 1day 2hours 3mins 4sec to 01jan2020:00:00:00 ?

01jan2020:00:00:00

IF I INCREMENT 1DAY 2HRS 3MINS 4SECS WHAT IS THE OUTPUT? AND HOW TO ADD ?

CAN I GET CODE PLEASE, HIGHLY APPRECIATED...

3 REPLIES 3
Diamond | Level 26

## Re: How to add 1day 2hours 3mins 4sec to 01jan2020:00:00:00 ?

``````data example;
datetime='01jan2020:00:00:00'dt;
incremented_datetime= datetime
+ 24*60*60 /* adds one day, in seconds */
+ 2*60*60 /* adds two hours, in seconds */
+ 3*60 /* adds 3 minutes, in seconds */
+ 4 /* adds four seconds */ ;
format datetime incremented_datetime datetime16.;
run;``````
--
Paige Miller
Tourmaline | Level 20

## Re: How to add 1day 2hours 3mins 4sec to 01jan2020:00:00:00 ?

``````data test;
dt='01jan2020:00:00:00'dt;
increment=1;
dt=intnx('dtday',dt,increment)+'2:3:4't;
format dt datetime20.;
run;``````

## Re: How to add 1day 2hours 3mins 4sec to 01jan2020:00:00:00 ?

Durations can be stored as date-time,

``````34         data _null_;
35            dt = dhms('01jan2020'd,0,0,0);
36            duration = dhms(1,2,3,4);
37            x  = sum(dt,duration);
38            put (dt duration x) (=datetime22.) duration=time12.;
39            run;

dt=01JAN2020:00:00:00 duration=02JAN1960:02:03:04 x=02JAN2020:02:03:04 duration=26:03:04``````
Discussion stats
• 3 replies
• 495 views
• 7 likes
• 4 in conversation