Checking a date is today or in the future

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
hame22
Forum Contributor
Posts: 214
Joined: Wed May 11, 2005 5:50 am

Checking a date is today or in the future

Post by hame22 »

Hi I have varibales, $day, $month, $year that a form posts to the page

I am trying to validate that the date they have posted is not in the past, is there a function for this?

A smiliar function I am using is checkdate() i was wondering if there was an equivilant for this purpose

Thanks in advance
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

User avatar
DaveTheAve
Forum Contributor
Posts: 385
Joined: Tue Oct 03, 2006 2:25 pm
Location: 127.0.0.1
Contact:

Post by DaveTheAve »

Here combind them together in a way you can use strtotime(); to get the unix timestamp. Once you have the unix timestamp juxtapose that to the timestamp you get from time();. If strtotime(); is larger then time(); your time is in the future.

It's that easy.

Edit: Errr, volka. I thought I had first post too. lol
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

How accurate are you looking to be? Server time settings and client system time settings need to be considered when doing time checks like this. Also, are you looking for a posting that is greater than or equal to right now, or just today's date?
Post Reply