Jump to content

[SOLVED] PHP checking dates


limitphp

Recommended Posts

I have a table with a date field.

I will be running queries on this table that will constantly be checking to see if the dates are newer than 24 hours, 7 days, 14 days, 21 days, 30 days, 60 days, 365 days.

 

Will it be easier to set the date field in the table as an INT and use strtotime (unix timestamps) to do all the comparisons?

or keep the date field as type date and do the comparisons a different way?

 

Thanks.

Link to comment
Share on other sites

you can just use strtotime('mysqlDateField')

 

to get the same data

 

So, leave them as standard dates in the date field (2008-11-04) and just convert them in the query in the php code?

 

How would you, for instance check a unix timestamp int if it was new than 24 hours or 7 days?

 

Thanks.

Link to comment
Share on other sites

Any PHP date stamp (time(), strtotime(), mktime(), etc.) returns the number of seconds since Jan. 1st, 1970. So, simply create two PHP time stamps and compare them. The difference will be the number of seconds that separate them. Then, just apply logic to determine minutes, hours, days, or whatever between them. here's a great reference:

http://www.w3schools.com/php/php_ref_date.asp

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.