Jump to content

[SOLVED] Help me understand what these codes mean.


Scorptique

Recommended Posts

Hey all, I need help understand the codes. This set of codes work, they basically display the upcoming birthdays from my contact list.

 

$sql = "select cl_id, cl_fname, cl_lname, cl_email, date_format(cl_dob, '%d %b %Y') AS cl_dob,
(TO_DAYS((cl_dob + INTERVAL (YEAR(CURRENT_DATE)-YEAR(cl_dob) + (RIGHT(CURRENT_DATE,5)>
RIGHT(cl_dob,5))) YEAR)) - TO_DAYS(CURRENT_DATE)) as daysAway from contact_list where
username = '$username' order by daysAway DESC";

 

But...i dont really understand (TO_DAYS((cl_dob + INTERVAL (YEAR(CURRENT_DATE)-YEAR(cl_dob) + (RIGHT(CURRENT_DATE,5)>RIGHT(cl_dob,5))) YEAR)) - TO_DAYS(CURRENT_DATE)). if you understand, can you explain to me please? Thanks! ^^;;

Link to comment
Share on other sites

So let's take it from outside to inside

 

If you drop outermost parentheses (), you will see, that there are two TO_DAYS() functions

 

TO_DAYS((cl_dob....)  -  TO_DAYS(CURRENT_DATE)

 

So, we have a number of days since year 0 calculated for the some date in the first function, and then number of days since year 0 for today substracted from it.

So basically it is a number of days between tha date in first function, and today.

 

Let's go some deeper into this first TO_DAYS() function

 

cl_dob + INTERVAL (YEAR(CURRENT_DATE)-YEAR(cl_dob) + (RIGHT(CURRENT_DATE,5)>RIGHT(cl_dob,5))) YEAR

 

So we now have two expressions added together.

 

cl_dob

This comes from table

 

INTERVAL (YEAR(CURRENT_DATE)-YEAR(cl_dob) + (RIGHT(CURRENT_DATE,5)>RIGHT(cl_dob,5)))

 

This one is strange, because INTERVAL() should have at least two arguments... you sure this is right?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.