Jump to content

Date issue in search


DavidRoberts60

Recommended Posts

I have a field in my MySQL database that is a timestamp. So when it is pulled onto the PHP page it looks something like 2011-10-28 10:46:47.

 

Obviously this looks ugly on the page so I do:

 

$jobtime2 = date("M j Y", strtotime($row["jobtime"]));

 

to make it look nice so it looks like Nov 3 2011.

 

I presume if I want to search for all records between 2 dates I use a form and in the SELECT statement use BETWEEN or do something like:

 

SELECT fields from table WHERE jobtime >= '$starttime' AND jobtime <= '$endtime';

 

however, if the 2 dates passed through via the form are Oct 1 2011 and Nov 1 2011 for example, it won't work, presumably because it wants input in the form 2011-10-28 10:46:47.

 

So what do I do?

 

Thanks

Link to comment
Share on other sites

convert it to a time:

 

$starttime = date("Y-m-d H:i:s", strtotime($_POST['date']));

 

This isn't the best solution, because not everything will be converted properly. I would recommend having pre-define values that users can select, such as a drop down, or separate input fields that each get validated as a month, day or year.

Link to comment
Share on other sites

convert it to a time:

 

$starttime = date("Y-m-d H:i:s", strtotime($_POST['date']));

 

This isn't the best solution, because not everything will be converted properly. I would recommend having pre-define values that users can select, such as a drop down, or separate input fields that each get validated as a month, day or year.

 

Wouldn't that be a lot of work?

 

So say I have one drop down for days of the month, one for months of the year and one for the year. How would that work? I'd need to check all three separately?

 

Thanks

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.