Jueves, 30 Enero 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
)

Visto 23359 veces Modificado por última vez en Jueves, 30 Enero 2014 12:04
Más en esta categoría: Search in system object »