datetime convert code example

Example 1: string to datetime convert

import datetime

date_time_str = '2018-06-29 08:15:27.243860'
date_time_obj = datetime.datetime.strptime(date_time_str, '%Y-%m-%d %H:%M:%S.%f')

print('Date:', date_time_obj.date())
print('Time:', date_time_obj.time())
print('Date-time:', date_time_obj)

Example 2: sql server convert string to date

Cast( '2011-07-07' as date ) as convertedDate

Example 3: SQL Date Format

SELECT FORMAT(dbo.column, 'M/dd/yyyy')

Example 4: convertir datetime a date

declare @fecha datetime 

set @fecha = GETDATE()

select convert(date ,@fecha)

Tags:

Sql Example