## DATE AND TIME

Solved
Super Contributor
Posts: 1,041

# DATE AND TIME

Hello Team,

I have date in one field and time in another..like shown in different formats. How can i combine both

DATE                                      TIME                                 ID

(DATETIME20. Formt)         (DATETIME22.3 FMT)

17DEC2014:00:00:00        01JAN190013:26:00.000    101

26DEC2014:00:00:00      01JAN1900:19:36:00.000    102

WANT: DATE_TIME LIKE SHOWN

DATE_TIME                                 ID

17DEC2014:13:26                     101

26DEC2014:19:36                     102

Regards

Accepted Solutions
Solution
‎06-17-2016 01:31 PM
Valued Guide
Posts: 534

## Re: DATE AND TIME

Hi @robertrao,

If both variables are datetimes you can use DATEPART() on the one and TIMEPART() on the other. Now you can combine them with DHMS(). In one line:

``datetime=dhms(datepart(date), 0, 0, timepart(time));``

Hope this helps,

- Jan.

All Replies
Solution
‎06-17-2016 01:31 PM
Valued Guide
Posts: 534

## Re: DATE AND TIME

Hi @robertrao,

If both variables are datetimes you can use DATEPART() on the one and TIMEPART() on the other. Now you can combine them with DHMS(). In one line:

``datetime=dhms(datepart(date), 0, 0, timepart(time));``

Hope this helps,

- Jan.

Super Contributor
Posts: 1,041

## Re: DATE AND TIME

``datetime=dhms(datepart(date), 0, 0, timepart(time));``

The above work pretty well. But I dint find an explanation online as to why the two zeros are being used in between. The documentation didnt explain it either.

Thanks

Valued Guide
Posts: 534

## Re: DATE AND TIME

The doc does explain this kind of use of DHMS() and especially using a time variable for the fourth parameter.

See the online doc of the DHMS function:

" The DHMS function returns a numeric value that represents a SAS datetime value. This numeric value can be either positive or negative.
You can also use the DHMS function to combine a SAS date value with a SAS time value to produce a SAS time value. Because a SAS time value is stored in seconds, you can specify 0 for the hour variable and 0 for the minute variable to return the correct value. Here is the syntax:"

`DHMS(SAS date, 0, 0, SAS time).`

Hope this clears things up a bit,

- Jan.

Valued Guide
Posts: 534

## Re: DATE AND TIME

Also it looks like you have not accepted my solution but instead a quote from it by yourself.

Valued Guide
Posts: 534

## Re: DATE AND TIME

Thanks @robertrao for setting that right.

Super User
Posts: 13,583