Jump to content

Date Format Help


paulspoon

Recommended Posts

I suppose the date is not generated but inputted by the costumers. You could use:

[code]
<?php
  $notGood = "20060710";
  $match = array();
  if(preg_match('/^([0-9]){4}([0-9]){2}([0-9]){2})/', $notGood, $match)) {
    $good = $match[0] . "/" . $match[1] . "/" . $match[2];
  }

  echo notGood . " - " . $good;
?>
[/code]

Or you could use following aswell:
[code]
<?php
  $notGood = "20060710";
  $match = array();
  if(preg_match('/^([0-9]){4}([0-9]){2}([0-9]){2})/', $notGood, $match)) {
    $good = date('YYYY/m/d', mktime('', '', '', $match[1], $match[2], $match[0]));
  }
  echo $good;
?>
[/code]
Link to comment
https://forums.phpfreaks.com/topic/14454-date-format-help/#findComment-57157
Share on other sites

Just tested it and is working:

[code]
<?php
  $notGood = "20060710";
  $match = array();
  $good = "";
  if(preg_match('/^([0-9]){4}([0-9]){2}([0-9]){2}/', $notGood, $match)) {
    $good = date('Y/m/d', mktime('', '', '', $match[1], $match[2], $match[0]));
  }
  echo $good;
?>
[/code]

Also working:
[code]
<?php
  $notGood = "20060710";
  $match = array();
  if(preg_match('/^([0-9]){4}([0-9]){2}([0-9]){2}/', $notGood, $match)) {
    $good = $match[0] . "/" . $match[1] . "/" . $match[2];
  }

  echo $notGood . " - " . $good;
?>
[/code]

Sorry, was forgotten some $ signs and had a ) sign too much in.
Link to comment
https://forums.phpfreaks.com/topic/14454-date-format-help/#findComment-57179
Share on other sites

$datefromdb = $sominhere['time_data'];
$year = substr($datefromdb,0,4);
$mon  = substr($datefromdb,4,2);
$day  = substr($datefromdb,6,2);
$hour = substr($datefromdb,8,2);
$min  = substr($datefromdb,10,2);
$sec  = substr($datefromdb,12,2);
$orgdate = date("l F dS, Y h:i A",mktime($hour,$min,$sec,$mon,$day,$year));
?>
Date: <? echo $orgdate; ?>
Link to comment
https://forums.phpfreaks.com/topic/14454-date-format-help/#findComment-57180
Share on other sites

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.