Is there any easy way to format a given date string? I see that the date() function can format a date, but it expects a timestamp, and I only have the string value pulled from a DB.
When I run date('m/d/Y', "2006-05-09"), it does not recogize the date and instead gives me the Unix epoch (I'm on Linux). This is, however, the way the vast majority of all the dates I'll be dealing with are formatting - they were originally human-friendly (e.g. 5/9/2006), were stuffed into a DB, and are now being pulled out and displayed - so I'm looking for the proper, elegant way to deal with this.
Format a given date? [SOLVED]
Moderator: General Moderators
-
tomprogers
- Forum Commoner
- Posts: 50
- Joined: Fri Mar 17, 2006 5:17 pm
- Location: Minnesota
- Contact:
Format a given date? [SOLVED]
Last edited by tomprogers on Thu May 11, 2006 12:29 pm, edited 1 time in total.
-
litebearer
- Forum Contributor
- Posts: 194
- Joined: Sat Mar 27, 2004 5:54 am
Try
or more simply
Code: Select all
<?PHP
$ts = time("2006-05-09");
echo date('m/d/Y', $ts);
?>Code: Select all
<?PHP
echo date('m/d/Y', time("2006-05-09"));
?>- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
If you are getting the date from a database don't forget to look at MySql date functions.
-
tomprogers
- Forum Commoner
- Posts: 50
- Joined: Fri Mar 17, 2006 5:17 pm
- Location: Minnesota
- Contact:
I'm using PostgreSQL, not MySQL. 8-(hawleyjr wrote:If you are getting the date from a database don't forget to look at MySql date functions.
tomprogers wrote:I'm using PostgreSQL, not MySQL. 8-(hawleyjr wrote:If you are getting the date from a database don't forget to look at MySql date functions.
PostgreSQL has all the functions you need also
http://www.postgresql.org/docs/8.0/inte ... etime.htmlto_char(current_timestamp, 'Day, DD HH12:MI:SS')
http://www.postgresql.org/docs/8.0/inte ... tting.html
-
tomprogers
- Forum Commoner
- Posts: 50
- Joined: Fri Mar 17, 2006 5:17 pm
- Location: Minnesota
- Contact: