Jump to content

Recommended Posts

Hi Guys,

 

On my site I have a Javascript calendar which picks up the date in a YYYY-MM-DD format and searches my database for a story for the date picked.

 

Now when this date is selected I want it to return all results where the date is less or equal to now().

 

And using this query the system worked:

 

$sql = "SELECT  * FROM cms_stories WHERE section LIKE '%$section%' AND published_web_date LIKE '%$published_web_date%' AND published_web_date <= NOW()";

 

However, I’ve now updated my database so that the field published_web_date is in the type of a timestamp – rather than a date as it was before.

 

So how can I change the query above to ask it do the same thing, but now it searching on a timestamp rather than a date field?

 

Thanks

 

Chris 

Link to comment
https://forums.phpfreaks.com/topic/49963-solved-date-problem/
Share on other sites

Yep.  Thank you.  It is in this type of format:

 

2007-04-26 16:24:27

(timestamp)

 

 

$sql = "SELECT  * FROM cms_stories WHERE section LIKE '%$section%' AND DATE_FORMAT(published_web_date,'%Y-%m-%d') LIKE '%$published_web_date%' AND published_web_date <= NOW()";

 

Try and let me know it works or not.

Link to comment
https://forums.phpfreaks.com/topic/49963-solved-date-problem/#findComment-245293
Share on other sites

Just take a look to ur date in db, it is in the format of 2007-04-26 time,

Date_format() is to extract date in the form of what u wish (in the function)

DATE_FORMAT(date_publish,'%Y-%m-%d')

%Y will show year in four digits like 2007,2000,1995

%m will show the month in two digits like 01,08,12

%d will show the day in two digits like 05,15,20

 

Now take a look on ur date format in db it is 2007-04-26.

Other thing is - ,in ur date u save it as 2007-04-26 not as 2007/04/26.

 

So the DATE_FORMAT(date_publish,'%Y-%m-%d')

 

Hope this will help u.

Link to comment
https://forums.phpfreaks.com/topic/49963-solved-date-problem/#findComment-245309
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.