Jump to content


Photo

Testing against a date...*SOLVED*


  • Please log in to reply
6 replies to this topic

#1 pocobueno1388

pocobueno1388
  • Members
  • PipPipPip
  • Advanced Member
  • 3,369 posts
  • LocationPalm Beach, Florida

Posted 01 October 2006 - 06:10 PM

Thanks to everyone who helped me with my last question, but after I fixed that I ran into another problem with the date, I am not very good at all with working with dates in PHP.

What my script does is when a user clicks a button which holds an ID of a dog, it will breed the dog and insert a date into the database which is 7 days from the date they just clicked the button.

What I want to do is next time they click the button to breed the dog is test whether the date in the database (which holds the date 7 days after they clicked last time) is either equal to todays date or if the current date has not reached the date in the database. If this is true it will display an error saying "You have already bred this dog in the last 7 days!".

I have tried doing this myself but it always displays the error message "You have already bred this dog in the last 7 days!"  whether it has been 7 days or not.
Here is my attempted code:

$today = date ('Y/m/d', strtotime ("U"));

if ($row3['next_breed'] < $today){
	echo "<table class='main'><td class='main'>You must wait a week to breed this female again!<p>
She may be bred again on $row3[next_breed]</td></table>";
exit;
}

$row3['next_breed'] is what holds the date +7 days from when they clicked the button last.

I am not sure if the default 'Date' in the database will effect anything. If they have never clicked the button the default date is obviously 0000-00-00, but I don't think that is the problem...it may be though.

Let me know what you guys think =) Thanks.

All help is greatly appreciated xP

#2 pocobueno1388

pocobueno1388
  • Members
  • PipPipPip
  • Advanced Member
  • 3,369 posts
  • LocationPalm Beach, Florida

Posted 01 October 2006 - 08:13 PM

anyone?

#3 sasa

sasa
  • Staff Alumni
  • Advanced Member
  • 2,804 posts
  • LocationHrvatska

Posted 01 October 2006 - 08:24 PM

try
$today = date ('Y-m-d', strtotime ("U"));


#4 pocobueno1388

pocobueno1388
  • Members
  • PipPipPip
  • Advanced Member
  • 3,369 posts
  • LocationPalm Beach, Florida

Posted 01 October 2006 - 08:28 PM

That gives me the same exact result ;)

#5 sasa

sasa
  • Staff Alumni
  • Advanced Member
  • 2,804 posts
  • LocationHrvatska

Posted 01 October 2006 - 08:39 PM

if ($row3['next_breed'] < $today){
is it Ok
i think thet you must use >

#6 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 01 October 2006 - 08:40 PM

Shouldn't

if ($row3['next_breed'] < $today){

be

if ($row3['next_breed'] > $today){
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#7 pocobueno1388

pocobueno1388
  • Members
  • PipPipPip
  • Advanced Member
  • 3,369 posts
  • LocationPalm Beach, Florida

Posted 01 October 2006 - 08:57 PM

Woah, talk about another brain fart. Thank you guys =) I thought I was switching that sign around to try to solve it...but I guess i was doing something wrong =/




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users