start with http://php.net/strtotime and http://php.net/date

<?
// many lines
$d = '2003-01-16';              // from mysql
$ds = strtotime($d);            // unix stamp
$df = date('l, F dS, Y',$ds);   // formatted
echo $df;
?>

OR

<?
//one line
echo date('l, F dS, Y',strtotime('2003-01-16'));
?>

For the 24hr time to 12hr time conversion, something like:

<?
$t = '22:17:48';
list($h,$m,$s) = explode(':',$t);
if($h >= 12) { $suffix = 'pm'; } else { $suffix = 'am'; }
if($h > 12) { $h = $h - 12; }
echo "{$h}:{$m}{$suffix}";
?>

Untested code of course, but it should do the job, and would be easy to wrap
into a re-useable function :)


Timezones:  I haven't looked into them too much, but you should consider
storing every date in GMT, rather than 'picking' a timezone to suit
everyone, which is of course impossible.  I think you can add the keyword
GMT to strtotime to achieve this.

strtotime() gives you a number of seconds since 1970... It's pretty
convenient to work with (but not for a human to read), because to add an
hour to the date, you just add 3600 (60s * 60m) to the number.  There must
be a way of finding out how many hours ahead/behind the GMT the user is, and
using that figure (3 hours = 3 x 3600) to alter the stamp to reflect their
time.

And then let's talk about daylight savings :)


If I were you, I'd just implement everything in GMT, unless you want to
spend a little while sorting all this out.


Justin




on 17/01/03 12:16 PM, Stephen ([EMAIL PROTECTED]) wrote:

> I have a PHP driven site that as a time schedule. Since the site isn't exactly
> filled with very intellagent people who just LOVE to translate times and dates
> from a weird format (Such as the format used in MySQL), I'd like to take these
> from a MySQL table (the table's types are DATE and TIME) and translate the
> date to something like "Thrusday, January 16th, 2003" when the date strate
> from the table is "2003-01-16." Then with time, I'd like it to read something
> like "8:00 PM" when it reads straight from the table "20:00:00." Another
> feature I'd like to have it timezones but that's not the point of this
> message. If you don't mind, though, could you also tell me how to configure
> the times according the the timezone a user has chosen?
> 
> Thanks,
> Stephen Craton
> http://www.melchior.us
> 
> "What's the point in appearance if your true love, doesn't care about it?" --
> http://www.melchior.us


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to