October 7, 2010 at 8:25 pm
How can i get the date and the month from a DateTime field ?
my goal was like this.
I have a PersonBirthDate from Personnel Table, user can select interval of time as they wanted. For example user set startDate = '12/01/2009' and the endDate is '14/09/2010'. I intended to display PersonName and PersonAdress who their birthday is between 12/01 amd 14/09 (only the date and the month).
Is there any suggestion for me ?
thx in advance.
Johan.
October 7, 2010 at 9:54 pm
Use the CONVERT function, with style 101, to convert the datetime to mm/dd/yyyy format. Grab just the first 5 characters, and then do your comparison.
Wayne
Microsoft Certified Master: SQL Server 2008
Author - SQL Server T-SQL Recipes
October 7, 2010 at 11:38 pm
Hi, thx for your reply.
It seem's doest work for me.
i've do as you suggest to me, and produce a query like below :
select PerBirthDate from UDPersonnel where Convert(varchar(5),PerBirthDate,101) <= Convert(varchar(5),'12/05/2010',101)
and the PerBirthDate
1965-06-19 00:00:00.000 <--
1965-06-18 00:00:00.000 <--
1977-03-18 00:00:00.000
1965-06-15 00:00:00.000 <--
1965-07-15 00:00:00.000 <--
1975-06-15 00:00:00.000 <--
which supposed not to be exist still appear.
any other suggestion for me ?
thx, regards.
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply