Jump to content

Need to pull records today plus 14 days using Month/Day only


Recommended Posts

I have a php script that pulls names and dates from my database. the trouble is, it's a genealogy database so BirthMonth, BirthDate, and BirthYear are separate columns (integers). I can't use Date or Year because years before 1900 are not recognized as valid.

 

I'd like to see results like:

Bob Smith    11  27  1810

Jim Davis      11  29  1965

David Jones 12    2    1919

Jane Doe    12    3    2009

Mary Smith  12 10    1845

 

Obviously the year is just an integer value; no math is done on it. Any advice? I really run into trouble when the selection runs into the next month - like today (11/27) through 12/11.

 

Many thanks in advance,

Weeble

 

Weeblesue,

  If you can translate that from month/date to dayofyear, you will almost have it solved. For a rough translation, you could use ((month - 1) * 30) + day. That would remove months from the problem, then the only problem would be dec17-dec31 overlapping into jan.

 

  I don't have the last piece of the answer, but hopefully that helps somewhat. :)

-YB

Why not store it as a properly formatted date, in a DATE field type in the database? That would give you a valid date range of 1000-01-01 through 9999-12-31

If you decide to go that route, you can add another field as a DATE field, then go through the table all at once and insert the date from the current fields.

UPDATE `table` SET `new_date_field` = (SELECT CONCAT_WS('-', `old_year`, `old_month`, `old_day`))

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.