Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > PHP How-To
|
PHP How-To Post your "How do I do this with PHP?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP How-To 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 August 18th, 2003, 02:52 AM
Authorized User
 
Join Date: Aug 2003
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default Format Date Time

Dear Experts,

I have a problem with formating a timestamp field which is retrieved from postgresql timestamp field.

When I print the value it shows as below:

echo $result['adddate'];

Mon 18 Aug 02:06:33.825621 2003

They way I want it is just Mon 18 Aug 2003.

I have tried with

echo date( 'l, d, n, Y', strtotime($result['adddate']));

Thursday, 01, 1, 1970

It prints invalid date. How do I format the date?

Please help.

Regards,
ganesh


 
Old August 18th, 2003, 02:10 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
Default

My first suggestion is to rewrite your query to return something you can use. If that's not an option, you'll need to extract the pieces yourself using regular expressions or some similar approach.

For example:

$pattern = '/(\w+)\s+(\d+)\s+(\w+)\s+[\d:\.]+\s+(\d+)/';
$replace = '${1} ${2} ${3} ${4}
echo preg_replace($pattern, $replace, $result['adddate']);

*should* print "Mon 18 Aug 2003".



Take care,

Nik
http://www.bigaction.org/
 
Old August 20th, 2003, 05:26 AM
Authorized User
 
Join Date: Aug 2003
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks a lot, it works.






Similar Threads
Thread Thread Starter Forum Replies Last Post
date time format vb certified Pro VB 6 4 December 18th, 2009 08:16 AM
Date/Time format & multiple selection with listbox frmsasp ASP.NET 1.0 and 1.1 Basics 0 October 13th, 2005 05:50 AM
Using xs:time to generate time in desired format krayan001 XSLT 0 June 27th, 2005 04:28 PM
Behavior of Date/Time Format Differs When Accessed Oliver Dempsey Classic ASP Basics 25 May 2nd, 2005 01:24 AM
Format Date to time field KennethMungwira VB.NET 3 November 17th, 2003 11:48 AM





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