Jump to content

Archived

This topic is now archived and is closed to further replies.

spires

DATE, shoud be a quick question.

Recommended Posts

Hi,

I have submitted the date into my database using:
[code]
$date = date("Y-m-d > H:i:s");
[/code]

Now my customer wants the date to read:
[code]
$date = date("d-m-Y > H:i:s");
[/code]

how can i change this when pulling the data out of the database?
Can this be done, or does it have to be before?

Thanks for all your help.

Share this post


Link to post
Share on other sites
is this help [code]<?php
function change_date_format($date) {
$date = explode(' > ',$date);
return implode('-',array_reverse(explode('-',$date[0]))).' > '.$date[1];
}

$date = date("Y-m-d > H:i:s");
echo change_date_format($date)."<br />\n";

?>[/code]

Share this post


Link to post
Share on other sites
[quote author=shivabharat link=topic=110385.msg446098#msg446098 date=1159893099]
Hi, If you are using MySQL refer DATE_FORMAT(date,format)  function.
[/quote]

I would suggest to store a UNIX timestamp instead, that makes it easier to sort dates, format it different formats using date() etc.

Share this post


Link to post
Share on other sites
[quote author=Daniel0 link=topic=110385.msg446178#msg446178 date=1159899734]
I would suggest to store a UNIX timestamp instead, that makes it easier to sort dates, format it different formats using date() etc.
[/quote]

definitely the best practice, but if you can't, you could just use this to print it after you take it out:
[code]
<?php
$date = date('Y-m-d > H:i:s');
list($date, $time) = explode(" > ", $date);
$new = date('d-m-Y > H:i:s', strtotime("$date $time"));
echo $new;
?>
[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.