Jump to content


Photo

change from yyyy-mm-dd hh:mm:ss to yyyymmddhhmmss format


  • Please log in to reply
3 replies to this topic

#1 JonathanAnon

JonathanAnon
  • Members
  • PipPip
  • Member
  • 13 posts

Posted 27 March 2006 - 05:46 PM

Hi,

i pull a timestamp from my mysql database and it is formatted as yyyy-mm-dd hh:mm:ss automatically.
How can I convert this to yyyymmddhhmmss easily?

regards,
J

#2 redbullmarky

redbullmarky
  • Staff Alumni
  • Advanced Member
  • 2,863 posts
  • LocationBedfordshire, England

Posted 27 March 2006 - 05:55 PM

[!--quoteo(post=358971:date=Mar 27 2006, 06:46 PM:name=JonathanAnon)--][div class=\'quotetop\']QUOTE(JonathanAnon @ Mar 27 2006, 06:46 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Hi,

i pull a timestamp from my mysql database and it is formatted as yyyy-mm-dd hh:mm:ss automatically.
How can I convert this to yyyymmddhhmmss easily?

regards,
J
[/quote]

you mean just without the - and : ??
if so, this'll do it:

$date = "2006-03-27 18:54:31";

$date = preg_replace('/[\-\:]/', '', $date);

"you have to keep pissing in the wind to learn how to keep your shoes dry..."

I say old chap, that is rather amusing!

#3 JonathanAnon

JonathanAnon
  • Members
  • PipPip
  • Member
  • 13 posts

Posted 27 March 2006 - 06:06 PM


Perfect thanks very much. That was wrecking my head.

#4 obsidian

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

Posted 27 March 2006 - 06:41 PM

[!--quoteo(post=358977:date=Mar 27 2006, 01:06 PM:name=JonathanAnon)--][div class=\'quotetop\']QUOTE(JonathanAnon @ Mar 27 2006, 01:06 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Perfect thanks very much. That was wrecking my head.
[/quote]

also, if you cared to actually calculate the new format (which i DO NOT recommend in this case because of additional overhead), study the following:
$date = "2006-03-27 18:54:31";
echo date('YmdHis', strtotime($date));

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