SoftadminUtil.DateTime_FromDateAndTime

Type: Scalar function

Creates a datetime2(7) value with the date part from the first parameter and the time part from the second parameter.

Examples

Combine a date and a time

DECLARE
	@Date date = '2020-03-19',
	@Time time = '11:45',
	@NewDateTime datetime2(7);

SELECT @NewDateTime = SoftadminUtil.DateTime_FromDateAndTime(@Date, @Time); -- 2020-03-19 11:45

Set the date part of a datetime

This can be useful when moving a calendar item to a new date without changing the time.

DECLARE
	@DateTime datetime2(7) = '2020-03-19 11:45',
	@Date date             = '2019-12-31',
	@NewDateTime datetime2(7);

SELECT @NewDateTime = SoftadminUtil.DateTime_FromDateAndTime(@Date, @DateTime); -- 2019-12-31 11:45

Set the time part of a datetime

DECLARE
	@DateTime datetime2(7) = '2020-03-19 11:45',
	@Time time             = '09:17',
	@NewDateTime datetime2(7);

SELECT @NewDateTime = SoftadminUtil.DateTime_FromDateAndTime(@DateTime, @Time); -- 2020-03-19 09:17

Parameters

@Date mandatory datetime
The date to use. The time part is ignored.
@Time mandatory datetime
The time to use. The date part is ignored.