Jump to content

[SOLVED] Date problem


Mr Chris

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.