Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> PHP
Author Message
tommyb
Hangin' Around



Joined: May 31, 2006
Posts: 49

PostPosted: Thu May 31, 2007 4:56 am Reply with quote

Hi,

I'm trying to compare a couple of dates in PHP using the following.
$sm is the selected month
$sd is the selected day
and $sy is the selected year.

I have tried
$actual = strtotime(date('d-m-Y')); as well.


Code:


$selected = strtotime(date('d-m-Y',mktime(0,0,0,$sm,$sd,$sy)));
$actual = strtotime(date('d-m-Y'),mktime(0,0,0,date('m'),date('d'),date('Y')));


Now todays date is 31/05/2007
if I select the date as 01/06/2007 it still tells me the date is smaller then the
30/05/2007 but this is not the case obviously.

If however I selected the 31/07/2007 it says the date is greater. Now it seems to me that is it going wrong somewhere when comparing the first part of the date i.e(the day).

Can anyone see what/where this is going wrong and how to fix it?

Many Thanks
 
View user's profile Send private message
tommyb







PostPosted: Thu May 31, 2007 5:05 am Reply with quote

Nevermind I sorted it by making the date go y-m-d and also i think i might have put a brace in somewhere i shouldnt have.

The code now looks like this

Code:


$selected = strtotime(date('Y-m-d',mktime(0,0,0,$sm,$sd,$sy)));
$actual = strtotime(date('Y-m-d'));
 
Gremmie
Former Moderator in Good Standing



Joined: Apr 06, 2006
Posts: 2415
Location: Iowa, USA

PostPosted: Thu May 31, 2007 8:00 am Reply with quote

You are jumping through some extra hoops for $selected. This should work as well:

Code:


$selected = mktime(0, 0, 0, $sm, $sd, $sy);
$actual = strtotime(date('Y-m-d'));

_________________
Only registered users can see links on this board! Get registered or login! - An Event Calendar for PHP-Nuke
Only registered users can see links on this board! Get registered or login! - A Google Maps Nuke Module 
View user's profile Send private message
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> PHP

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©