Jump to content


Photo

DATE, shoud be a quick question.


  • Please log in to reply
5 replies to this topic

#1 spires

spires
  • Members
  • PipPipPip
  • Advanced Member
  • 492 posts

Posted 03 October 2006 - 04:19 PM

Hi,

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

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

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.


How to make over $600 a day from AdSense? Discover EXACTLY how he does it in these videos:
http://www.adsense-online.com

#2 shivabharat

shivabharat
  • Members
  • PipPipPip
  • Advanced Member
  • 371 posts
  • LocationChennai, India

Posted 03 October 2006 - 04:31 PM

Hi, If you are using MySQL refer DATE_FORMAT(date,format)  function.
Knowledge --- Reading Enriches Mind But Sharing Enhances It.[br][br]Note: Before you request help enusre that you have had a look at the tutorials @phpfreaks

#3 spires

spires
  • Members
  • PipPipPip
  • Advanced Member
  • 492 posts

Posted 03 October 2006 - 04:33 PM

ok, thanks i'll try it.
How to make over $600 a day from AdSense? Discover EXACTLY how he does it in these videos:
http://www.adsense-online.com

#4 sasa

sasa
  • Staff Alumni
  • Advanced Member
  • 2,804 posts
  • LocationHrvatska

Posted 03 October 2006 - 06:01 PM

is this help
<?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";

?>


#5 Daniel0

Daniel0
  • Staff Alumni
  • Advanced Member
  • 11,956 posts

Posted 03 October 2006 - 06:22 PM

Hi, If you are using MySQL refer DATE_FORMAT(date,format)  function.


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

#6 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 03 October 2006 - 06:32 PM

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


definitely the best practice, but if you can't, you could just use this to print it after you take it out:
<?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;
?>

You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users