Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
Node is saved as draft in My Content >> Draft
  • To extract only Date from Date Time in SQL in particular format

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 48
    Comment on it

    In SQL we have situations where we want to extract date from date time and in particular format

    -- Extracting only Date from DateTime Type Column
    
    SELECT N.[ID],N.[Message],N.[LocationID],N.[TargetUserID],N.[Url],CONCAT(U.[FirstName],U.[LastName]) AS [CreatedBy],CONVERT(VARCHAR(20), N.[CreatedDate], 103) as [CreatedDate],N.[DaysTillExpire],N.[HoursTillExpire] 
    	FROM [NUDGE] AS N INNER JOIN  [User] AS U ON N.[CreatedBy]=U.[ID]
    	WHERE N.[LocationID]=0 
    	AND N.[TargetUserID]=@TargetUserID
    	AND N.[IsDeleted]=0 
    	AND N.[IsExpired]=0 
    	AND N.[IsCompleted]=0 
    Output:
    
    18,Creating nudge testing,0,19,NULL,jagandeep,23/02/2016,0,4

    Here Concatenation is done for merging first and last name

    For extracting Date in "dd/mm/yyyy"  format we have code 103

    In SQL we have different codes for different format

    1	101	1 = mm/dd/yy
    101 = mm/dd/yyyy 	USA
    
    2	102	2 = yy.mm.dd
    102 = yyyy.mm.dd	ANSI
    
    3	103	3 = dd/mm/yy
    103 = dd/mm/yyyy	British/French
    
    4	104	4 = dd.mm.yy
    104 = dd.mm.yyyy	German
    
    5	105	5 = dd-mm-yy
    105 = dd-mm-yyyy	Italian
    
    6	106	6 = dd mon yy
    106 = dd mon yyyy	
    -
    7	107	7 = Mon dd, yy
    107 = Mon dd, yyyy	-
    
    8	108	hh:mm:ss	-
    -	9 or 109	mon dd yyyy hh:mi:ss:mmmAM (or PM)
    	
    10	110	10 = mm-dd-yy
    110 = mm-dd-yyyy	USA
    
    11	111	11 = yy/mm/dd
    111 = yyyy/mm/dd	Japan
    
    12	112	12 = yymmdd
    112 = yyyymmdd	ISO
    
    -	13 or 113	dd mon yyyy hh:mi:ss:mmm (24h)	Europe default + millisec
    
    14	114	hh:mi:ss:mmm (24h)	

     

    SQL Server

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: