Show all Hide all

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


Combine a date and a time

	@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.

	@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

	@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
Type: Scalar function
Area of use: General use


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