How to select the records who are completed exactly years comparing with joining date and todays date
-
Hi, I have mysql database and employee details table is there with the column joining date. i need to write a query in mysql in such a way that i should compare joining date with today date since i need to display employee details who are going to complete exactly 1 yr, 2 yr , 3yr ... and so on. For ex: Joining_Date Current_Date Years_Completed 2010-05-26 2014-05-26 4 years 2000-05-26 2014-05-26 14 years 2010-04-26 2014-05-26 4 years this row should not come since one month is less only for todays date they should exactly complete years How to achieve this. If anybody knows, please reply me. Thanks in advance.
-
Hi, I have mysql database and employee details table is there with the column joining date. i need to write a query in mysql in such a way that i should compare joining date with today date since i need to display employee details who are going to complete exactly 1 yr, 2 yr , 3yr ... and so on. For ex: Joining_Date Current_Date Years_Completed 2010-05-26 2014-05-26 4 years 2000-05-26 2014-05-26 14 years 2010-04-26 2014-05-26 4 years this row should not come since one month is less only for todays date they should exactly complete years How to achieve this. If anybody knows, please reply me. Thanks in advance.
-
Hi, I have mysql database and employee details table is there with the column joining date. i need to write a query in mysql in such a way that i should compare joining date with today date since i need to display employee details who are going to complete exactly 1 yr, 2 yr , 3yr ... and so on. For ex: Joining_Date Current_Date Years_Completed 2010-05-26 2014-05-26 4 years 2000-05-26 2014-05-26 14 years 2010-04-26 2014-05-26 4 years this row should not come since one month is less only for todays date they should exactly complete years How to achieve this. If anybody knows, please reply me. Thanks in advance.
Don't know MySQL but you should be able to break the datetime object into day/month/year/time components. Select from the table where the day = day and the month = month, ignoring the year and time components.
Never underestimate the power of human stupidity RAH
-
What happens with the following joining dates if todays date is 2014-05-26 1. 2012-05-25 2. 2012-05-26 3. 2012-05-27 4. 2013-05-27
if todays date is 2014-05-26 then 1. 2012-05-25 if u consider 2 years means 730 (365 X 2) days will come but in this 731 that 2 years 1 day so we should display this, it should complete exactly year 2. 2012-05-26 i think this is coming 730 days means 2 years exactly we can display 3. 2012-05-27 in this 1 day required to complete exactly 2 years now it is 729 days 4. 2013-05-27 in this 364 is coming it should be 365 to complete a year so we should display this record How to achieve this. Please reply me.
-
Hi, I have mysql database and employee details table is there with the column joining date. i need to write a query in mysql in such a way that i should compare joining date with today date since i need to display employee details who are going to complete exactly 1 yr, 2 yr , 3yr ... and so on. For ex: Joining_Date Current_Date Years_Completed 2010-05-26 2014-05-26 4 years 2000-05-26 2014-05-26 14 years 2010-04-26 2014-05-26 4 years this row should not come since one month is less only for todays date they should exactly complete years How to achieve this. If anybody knows, please reply me. Thanks in advance.
You have to use date formatting in year
-
Hi, I have mysql database and employee details table is there with the column joining date. i need to write a query in mysql in such a way that i should compare joining date with today date since i need to display employee details who are going to complete exactly 1 yr, 2 yr , 3yr ... and so on. For ex: Joining_Date Current_Date Years_Completed 2010-05-26 2014-05-26 4 years 2000-05-26 2014-05-26 14 years 2010-04-26 2014-05-26 4 years this row should not come since one month is less only for todays date they should exactly complete years How to achieve this. If anybody knows, please reply me. Thanks in advance.
Hi, Try below :
DECLARE @JoiningDate DATE
SET @JoiningDate = '10/10/2013'IF (YEAR(GETDATE()) > YEAR(@JoiningDate))
BEGIN
IF (DAY(@JoiningDate) = DAY(GETDATE()) AND DAY(@JoiningDate) = DAY(GETDATE()))
BEGIN
/*
This will exceute on every year of joining date.
Below is the print statement to check the testing result.
*/
PRINT CONVERT(NVARCHAR,(YEAR(GETDATE()) - YEAR(@JoiningDate))) + ' Year(s)'
END
END