Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
|
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 16th, 2004, 08:00 AM
richard.york's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

I'd convert the stamps to Unix timestamps and then use PHP's date() function. I think you can retrieve the timestamp from the DB in unix time by applying a function there. You'd have to RTM though.

Otherwise there's strtotime.
http://www.php.net/strtotime

That (tries to) create a UNIX timestamp from any date string. Then you can format the date however you like. And then naturally you'd use,

mktime() > $data['timeend'];

so that you're comparing two Unix timestamps.

I'd try to extract the timestamp from the database already in unix timestamp form, since that'd be the most efficient approach.

HTH!


Regards,
Rich

--
[http://www.smilingsouls.net]
[http://pear.php.net/Mail_IMAP] A PHP/C-Client/PEAR solution for webmail
 
Old September 23rd, 2004, 01:40 PM
Authorized User
 
Join Date: Jun 2003
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Rich,
You were right about needing to convert the timestamps as now I can calculate the time differences properly: here's how I have done it (for anyone else looking for the solution):

Code:
Auction Started: 
<?php
$result2=mysql_query("SELECT UNIX_TIMESTAMP(timestarted) AS FORMATTED_STARTTIME FROM table where item=$_GET[item]"); 
$FORMATTED_STARTTIME=mysql_result($result2,0,"FORMATTED_STARTTIME"); 
$date1=date("l-j-F-Y H:i:sa",$FORMATTED_STARTTIME); 
echo "$date1"; ?>

Auction Ends: 
<?php 

$result3=mysql_query("SELECT UNIX_TIMESTAMP(timeend) AS FORMATTED_ENDTIME FROM table where item=$_GET[item]"); 
$FORMATTED_ENDTIME=mysql_result($result3,0,"FORMATTED_ENDTIME"); 
$date2=date("l-j-F-Y H:i:sa",$FORMATTED_ENDTIME); 
echo "$date2"; ?>
and then using:
$diff=$FORMATTED_ENDTIME-mktime();
to calculate the difference in seconds.

Thanks very much for your help
Sami





Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP and Javascript davidhayter Beginning PHP 5 May 6th, 2005 05:33 AM
javascript with php kuehhc Beginning PHP 8 February 1st, 2005 10:59 PM
How to use javascript with php? raichand_ray PHP How-To 2 November 12th, 2004 06:41 AM
PHP with Javascript Droobles Pro PHP 1 February 17th, 2004 03:08 PM
JavaScript and php Bandy PHP How-To 2 February 10th, 2004 04:32 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.