PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old October 15th, 2004, 09:57 AM
Hellcat1 Hellcat1 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 2 Hellcat1 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question Need help with comparing dates

I've been having trouble comparing dates with my code, for some reason it does not return the proper responce. I have several dates stored in my mySQL database (sebclose, ebclose, regclose, and closedate), in the default format, which I'm trying to compare to a datestamp so that as people view my page, it will display the code for that time frame. The problem I'm runing into, is that responce to my IF statements are not being returned correctly. Perhapse somebody will see what I'm doing wrong and can correct it.

the dates currently are
datestamp = 2004-10-15
sebclose = 0000-00-00
ebclose = 2004-09-30
regclose = 2004-10-31
closedate = 2004-10-31

$datestamp = date("Y-m-d");

if($myrow["sebhead"]!="" AND $myrow["sebclose"] >= '$datestamp' AND $myrow["sebclose"] != '0000-00-00'){Show SEBcode}

if($myrow["sebclose"]!="0000-00-00" AND $myrow["sebclose"] <= '$datestamp'){
}else{
if($myrow["ebhead"]!="" AND $myrow["ebclose"] >= '$datestamp' AND $myrow["ebclose"] != '0000-00-00'){Show EBcode}

if($myrow["reghead"]!="" AND $myrow["regclose"] >= '$datestamp' AND $myrow["ebclose"] < '$datestamp'){Show REGcode}

if($myrow["latehead"]!="" AND $myrow["closedate"] >= '$datestamp' AND $myrow["regclose"] < '$datestamp'){Show LATEcode}


Even though the server is reporting the correct date for the datestamp (2004-10-15) the if statement for EBcode is displaying and not REGcode.

Reply With Quote
  #2  
Old October 15th, 2004, 03:12 PM
Viper_SB's Avatar
Viper_SB Viper_SB is offline
Moderator
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: Canada
Posts: 330 Viper_SB User rank is Private First Class (20 - 50 Reputation Level)Viper_SB User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Day 4 h 51 m 6 sec
Reputation Power: 5
you are putting $datestamp inside single quotes so it won't get parased.

Reply With Quote
  #3  
Old October 15th, 2004, 05:07 PM
Hellcat1 Hellcat1 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 2 Hellcat1 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Talking

Thanks, that fixed it.

Reply With Quote
  #4  
Old October 17th, 2004, 10:46 AM
m3rajk m3rajk is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 24 m3rajk User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
why are you taking them out of sql to compare? use sql calls to compare them. compare IN SQL and you do not need to touch anything in php. that is the most efficient thing to do.


let's say you want all closed files
PHP Code:
 $sql="SELECT * FROM files WHERE closedate<NOW()"# sql query with comparison
 
$files=mysql_query($sql,$db); # sql call 

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > Need help with comparing dates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway