scriptygoddess

09 Sep, 2003

Date Time

Posted by: Jennifer In: Script snippet

Just wanted to store some code I use a lot and am tired of looking up 😉

In some of the scripts I work on, I create a field for a timestamp. For that field I insert the PHP value: time()

When recalling that value, it's just an ugly looking UNIX timestamp, so to format it to something nice, I do the following: (as posted on the PHP manual)

<?php
/*
Assuming the UNIX timestap was for : March 10th, 2001, 5:16:18 pm
and you already did a mysql query, and fetch_array
and the name of the field for timestamp, is 'timestamp'
*/
$today = date("F j, Y, g:i a", $row['timestamp']);
// March 10, 2001, 5:16 pm
$today = date("m.d.y", $row['timestamp']);
// 03.10.01
$today = date("Ymd", $row['timestamp']);
// 20010310
$today = date('\i\t \i\s \t\h\e jS \d\a\y.', $row['timestamp']);
// It is the 10th day.
$today = date("D M j G:i:s T Y", $row['timestamp']);
// Sat Mar 10 15:16:08 MST 2001
?>

No Responses to "Date Time"

Comments are closed.

Featured Sponsors

Genesis Framework for WordPress

Advertise Here


  • Scott: Just moved changed the site URL as WP's installed in a subfolder. Cookie clearance worked for me. Thanks!
  • Stephen Lareau: Hi great blog thanks. Just thought I would add that it helps to put target = like this:1-800-555-1212 and
  • Cord Blomquist: Jennifer, you may want to check out tp2wp.com, a new service my company just launched that converts TypePad and Movable Type export files into WordPre

About


Advertisements