Jun 6, 2001 1 #1 Fursten Programmer Joined Dec 27, 2000 Messages 403 Location PT I have one field of type datetime, and I would like to retrieve - with transact SQL only the date part (day, month and year). Is it possible? Thank you
I have one field of type datetime, and I would like to retrieve - with transact SQL only the date part (day, month and year). Is it possible? Thank you
Jun 6, 2001 #2 tlbroadbent MIS Joined Mar 16, 2001 Messages 9,982 Location US Select convert(char(10), datecol, 103) As DateOnly From tbl Style #103 returns date in dd/mm/yyyy format. Other styles are 101 - mm/dd/yyyy 107 - mmm dd yyyy (increase size from char(10) to char(11)) 112 - mmddyyyy (decrease size) See SQL BOL Convert and Cast topic for more info. Terry http://members.home.net/tlbroadbent/prog.htm------------------------------------ Experience is the hardest kind of teacher. It gives you the test first, and the lesson afterward. Upvote 0 Downvote
Select convert(char(10), datecol, 103) As DateOnly From tbl Style #103 returns date in dd/mm/yyyy format. Other styles are 101 - mm/dd/yyyy 107 - mmm dd yyyy (increase size from char(10) to char(11)) 112 - mmddyyyy (decrease size) See SQL BOL Convert and Cast topic for more info. Terry http://members.home.net/tlbroadbent/prog.htm------------------------------------ Experience is the hardest kind of teacher. It gives you the test first, and the lesson afterward.
Jun 7, 2001 #3 IonelBurtan Programmer Joined May 25, 2001 Messages 601 Location RO declare @CurentDate varchar(15) select @CurentDate = DATENAME(day, getdate()) + DATENAME(month, getdate()) + DATENAME(year, getdate()) with this code you can read the element of the current date (day, month, year). You could also use the DATEPART function. Try to adapt it to your needs, Hopr this helps,s-) Blessed is he who in the name of justice and good will, shepards the week through the valley of darknees... http://home.domaindlx.com/ionelb Upvote 0 Downvote
declare @CurentDate varchar(15) select @CurentDate = DATENAME(day, getdate()) + DATENAME(month, getdate()) + DATENAME(year, getdate()) with this code you can read the element of the current date (day, month, year). You could also use the DATEPART function. Try to adapt it to your needs, Hopr this helps,s-) Blessed is he who in the name of justice and good will, shepards the week through the valley of darknees... http://home.domaindlx.com/ionelb
Jan 16, 2002 #4 hirenJ Programmer Joined Dec 17, 2001 Messages 72 Location GB I dunno if this is valid -- but to do this in vb i use the left function: Dim date as str date= now() 'gets clock time and date date = left(date, 10) ' just retrieve the dd/mm/yyyy ) Upvote 0 Downvote
I dunno if this is valid -- but to do this in vb i use the left function: Dim date as str date= now() 'gets clock time and date date = left(date, 10) ' just retrieve the dd/mm/yyyy )