Jump to content


Photo

date problam


  • Please log in to reply
25 replies to this topic

#21 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 02 August 2006 - 04:53 AM

the logic of your code will do the same as this example then and more simple to understand.

is the reason that your code use less code becouse the time() statement is a timestamp and does not need the use of strtotime within it.
<?php

$db_time = "12:10:44";
$curr_time = date("h:i:s", time());
$get_date = '2006-01-01';

$timenow = strtotime($get_date." ".$curr_time);
$dbtime = strtotime($get_date." ".$db_time);

$d = date("M d, Y h:i:s", $dbtime);
$t = date("M d, Y h:i:s", $timenow);

if ($timenow > $dbtime){
echo'Booo smelly people!';
}

else{ 
echo'Hooray Beer!';
}

?>

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#22 akitchin

akitchin
  • Staff Alumni
  • Advanced Member
  • 2,516 posts
  • LocationCalgary, AB, Canada

Posted 02 August 2006 - 05:08 AM

you're still ignoring the fact that you NEVER WANT TO COMPARE STRING VERSIONS OF DATES.  you want to compare timestamps.  using your exact code, the following would do what you want (with both less ambiguity and more efficiency):

<?php
$db_time = "12:10:44";
$get_date = '2006-01-01';

$dbtime = strtotime($get_date." ".$db_time);

$timenow = time();

if ($timenow > $dbtime){
echo'Booo smelly people!';
}
else{ 
echo'Hooray Beer!';
}
?>

are you pulling $db_time and $get_date from the database?  if so, USE MYSQL'S FUNCTIONS!

your use of the last two date() functions is totally unnecessary, as this turns the date/time into a string format, and you  do not want to compare the string versions as they will not compare the DATES, they will compare the STRINGS.  that is, "August 14 2006 12:00:00" will be "less" than "June 14 2006 12:00:00" because "A" is less than "J" where strings are concerned.

#23 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 02 August 2006 - 05:18 AM

I totally agree with the mysql function but i am currently learning via php only at this point sorry.

Is the concept of what i am trying to learn for collage correct thats all and thank you so much.

<?php
$database_time="01:06:30";
$database_stamp($database_time);
$time_now=date("h:i:s",time()+3600);

if($time_now>$database_stamp) {

echo " i am larger";

}else{

echo" i am smaller";

}
?>

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#24 akitchin

akitchin
  • Staff Alumni
  • Advanced Member
  • 2,516 posts
  • LocationCalgary, AB, Canada

Posted 02 August 2006 - 05:35 AM

your current method is still incorrect, as you're using date() to create a STRING version of the timestamp you're calculating with time() + 3600.  you shouldn't need to use date() AT ALL in this calculation, as date() is used to create a STRING version of a timestamp.

$time_now=time()+3600;


#25 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 02 August 2006 - 05:40 AM


so this is correct and is the only way in php for a proper timestamp format.
<?php
$database_time="01:06:30";
$database_stamp($database_time);
$time_now=time()+3600;

if($time_now>$database_stamp) {

echo " i am larger";

}else{

echo" i am smaller";

}
?>

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#26 akitchin

akitchin
  • Staff Alumni
  • Advanced Member
  • 2,516 posts
  • LocationCalgary, AB, Canada

Posted 02 August 2006 - 07:26 PM

i have no idea what you're trying to achieve with:

$database_stamp($database_time);

that won't do anything.  in fact, i don't even know where you've gotten that from.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users