Giovedì, 30 Gennaio 2014 12:04

Convert a date to varchar

Share this post

This function return a varchar with the date and time from a datetime parameter.

The string returned is in french but can be adapted in other language.

CREATE FUNCTION [dbo].[ConvertDateToVarchar]
(	
	@Date DateTime
)
RETURNS TABLE 
AS
RETURN 
(
	SELECT	DateStr =	CASE	WHEN @Date Is Null THEN 'Jamais' 
								WHEN (DatePart(hour, @Date) = 0 AND DatePart(Minute, @date) = 0) THEN CONVERT(VARCHAR, @Date, 105)
						ELSE	CONVERT(VARCHAR, @Date, 105) + ' à ' + 
								REPLACE(CONVERT(VARCHAR(5), @Date, 108),':', 'h')
						END
)

Letto 23591 volte Ultima modifica il Giovedì, 30 Gennaio 2014 12:04
Altro in questa categoria: Search in system object »