Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.

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