Jump to content

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

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.