Jump to content

DATE, shoud be a quick question.


spires
 Share

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.

Link to comment
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]
Link to comment
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.
Link to comment
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]
Link to comment
Share on other sites

This thread is more than a year old. Are you sure you have something important to add to it?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

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.