Jump to content

Recommended Posts

Having issues coming up with the proper code/select statement.

My DB has three fields in particular. start_date_month, start_date_day, start_date_year.

I am trying to get results that are set to happen within a 2 week time period from today's date.

How would I go about coding this?

I did a $current_date = mktime(0,0,0, date('n'), date('d'), date('Y'));, but I am confused on how to get the right info from the DB.

Any help would be great!
Link to comment
https://forums.phpfreaks.com/topic/36263-phpmysql-select-statement-processing/
Share on other sites

I am I correct in thinking that you use 3 fields to store the date in your database ?
one field for year one for month and one for days ?

say you want to select the dates from january 2 2007 till 16 is easy
select * from table where year is 2007 and month is 01 and day is =< 02 and day is => 16

but you will run into trouble soon because not all the months have the same number of days.
I would suggest working with a date field in your database instead of the 3 separate fields.
that way you can use all the mysql date functions. (google for mysql date functions if you want to have an idea what is possible)
[quote]
My DB has three fields in particular. start_date_month, start_date_day, start_date_year.
[/quote]

Didn't catch that.  I would suggest consolidating these values in a date or datetime field.  Will make your life much easier when doing any sort of date arithmetic.

Patrick
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.