0

I currently have stored DateTime in the database as follows 20130208110000 so I need to break it into 2 parts which is date in this format 08/02/2013 and time in this format 11:00 AM, which function does this effectively?

This is the function I used to join both date and time together

$startMonth = $this->_getParam('starts_month_day_year');
$startTime = $this->_getParam('starts_time');
date("YmdHis",strtotime($startMonth.$startTime));
3
  • 4
    why dont use store the date in one of the db date\time field types and make life a lot esier Commented Feb 8, 2013 at 2:48
  • @Dagon hi its too late for modification as i planning to do changes on later time Commented Feb 8, 2013 at 2:50
  • 2
    its never to late to do things properly, you could convert then with a script in about 10 minutes Commented Feb 8, 2013 at 2:51

2 Answers 2

1
<?php
      $originalDate = "20130208110000";
      $newDate = date("d-m-Y g:i A", strtotime($originalDate));
      echo $newDate;  //08-02-2013 11:00 AM
?>

where,

g :12-hour format of an hour without leading zeros [0 through 12]

i :Minutes with leading zeros [00 through 59]

A:Uppercase Ante meridiem and Post meridiem [AM or PM]

Sign up to request clarification or add additional context in comments.

Comments

1

What would be wrong with just using what you're already doing?

$myDate = "20130208110000";
date("d/m/Y", strtotime($myDate)); // Date, e.g. 08/02/2013
date("h:i A", strtotime($myDate)); // Time, e.g. 11:00 AM

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.