Jump to content

date conversion


jas4

Recommended Posts

Hi, i've got a date coming into my webstite in the format:

 

HH:MM:SS DD Mmm YY,YYYY PST (looks like 4:29:05 Aug 23, 2007 PDT)

 

but I want it to convert it into a format for inserting into mysql either in DATE or TIMEDATE,

 

i thought about using explode, but there explode takes everything seperated by a certain character, but how can it be done if there are 2 different characters?

Link to comment
https://forums.phpfreaks.com/topic/66333-date-conversion/
Share on other sites

Try something like this:

<?php
function convertMyDate($date) {
  if (preg_match('|^([^\s]+)(.*)$|', $match)) {
    $time = $match[0];
    $date = $match[1];

    if (($ts = strtotime($date . $time)) !== FALSE) {
      return date('Y-d-m g:i:s', $ts);
    } else return FALSE; // invalid format
  } else return FALSE; // invalid format
}
?>

 

Hope that helps. Get familiar with the date/time conversion functions, and you can do almost anything you want. While this may not be exactly what you're after, it should definitely give you a push in the right direction.

Link to comment
https://forums.phpfreaks.com/topic/66333-date-conversion/#findComment-331982
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.