Jump to content

Time


cheechm

Recommended Posts

$timestamp_plushour = time() + 3600;
$formatted_date = date('H:i:s', $timestamp_plushour);
echo $formatted_date;

 

there are a zillion ways to skin the cat when it comes to dates and times; this is but one of them.

 

EDIT:  CV's brief post has beaten me to the punch - thine fingers are brisk, CV.

Link to comment
https://forums.phpfreaks.com/topic/124860-time/#findComment-645054
Share on other sites

Thanks, so I have this in my database:

 

time_visited = 21:00:00

 

How would I compare the current time using

        $time = time() + 3600;
        $expire_time = date('H:i:s', $time);

 

to time_visited?

 

Thanks

 

that only works for UNIX timestamps, which time() generates.  if your time is in the database in TIME format, you can simply use:

 

DATE_ADD(time_visited, INTERVAL 1 HOUR)

 

in MySQL itself.

Link to comment
https://forums.phpfreaks.com/topic/124860-time/#findComment-645070
Share on other sites

Doesn't work.. Hmmm....

 


        $time = time() + 3600;
        $expire_time = date('H:i:s', $time);
        $sql = "SELECT username FROM login WHERE DATE_ADD(last_visit_time, INTERVAL 1 HOUR) < $expire_time" or die(mysql_error
            ());
$result = db_query($sql);
        $users_online = array();
        while ($row = db_fetch_array($result)) {
        	echo $row['username'];
}

 

Thanks

 

 

Link to comment
https://forums.phpfreaks.com/topic/124860-time/#findComment-645083
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.