Jump to content

DATE, shoud be a quick question.


spires

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
https://forums.phpfreaks.com/topic/22886-date-shoud-be-a-quick-question/
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.
[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]

Archived

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

×
×
  • 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.