Welcome Guest, Not a member yet? Register   Sign In
sql query for days until next birthday?
#6

[eluser]sophistry[/eluser]
ok, major logic flaw in the previous version... comparing month number and day number is the wrong approach - it doesn't make sense and it gives wrong results.

here is the final version (just sending the SQL select since the other parts were fine):
Code:
$this->db->select("IF (
DATEDIFF( CONCAT_WS('-',YEAR($Ymd),MONTH(datetime_start),DAYOFMONTH(datetime_start)),$Ymd) >= 0,
    DATEDIFF( CONCAT_WS('-',YEAR($Ymd),MONTH(datetime_start),DAYOFMONTH(datetime_start)),$Ymd),
    DATEDIFF( CONCAT_WS('-',YEAR($Ymd)+1,MONTH(datetime_start),DAYOFMONTH(datetime_start)),$Ymd)
)
AS days_until_event", FALSE);


Messages In This Thread
sql query for days until next birthday? - by El Forum - 02-06-2009, 11:33 AM
sql query for days until next birthday? - by El Forum - 02-06-2009, 12:48 PM
sql query for days until next birthday? - by El Forum - 02-06-2009, 12:58 PM
sql query for days until next birthday? - by El Forum - 02-06-2009, 01:18 PM
sql query for days until next birthday? - by El Forum - 10-01-2009, 02:12 PM
sql query for days until next birthday? - by El Forum - 10-19-2009, 08:03 PM



Theme © iAndrew 2016 - Forum software by © MyBB