Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-28-2012, 11:11 PM   PM User | #1
moisesbr
New Coder

 
Join Date: Nov 2009
Posts: 44
Thanks: 0
Thanked 0 Times in 0 Posts
moisesbr is an unknown quantity at this point
Check if a date is in the past or future

HI

I have a form for reservation for courses where $data_course is the
date of the course.

I want to display error message if the date has already passed.

The problem is that it returns the error message even if the date is future.

Please let me know if there is any adust to do to the code below:

$today = getdate();

if($data_course < $today) { $errors[] = 'This course already happend';}


Moises

Last edited by moisesbr; 07-28-2012 at 11:15 PM..
moisesbr is offline   Reply With Quote
Old 07-28-2012, 11:17 PM   PM User | #2
DrDOS
Senior Coder

 
Join Date: Sep 2010
Posts: 1,155
Thanks: 10
Thanked 148 Times in 148 Posts
DrDOS is infamous around these parts
A simple way to deal with this is record the unix time of the reservation, which is just a number and can be subtracted for comparison.
DrDOS is offline   Reply With Quote
Old 07-28-2012, 11:55 PM   PM User | #3
moisesbr
New Coder

 
Join Date: Nov 2009
Posts: 44
Thanks: 0
Thanked 0 Times in 0 Posts
moisesbr is an unknown quantity at this point
I modified it as below:

$today = date("d-m-y");

I tested a future and paste date and it works ok.

Is it necessary to use strtotime function to prevent possible errors
or does it seem ok ?

Moises
moisesbr is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:39 PM.


Advertisement
Log in to turn off these ads.