Solved

covert time array to string

Posted on 2014-12-06
2
137 Views
Last Modified: 2014-12-07
In cakephp I have a inputted time that is in the form of an array
How do I convert this to a string as I need to compare it  and array comparisons dont work with time.


array(
      'hour' => '01',
      'min' => '00',
      'meridian' => 'pm'

I need this to be 13:00:00
0
Comment
Question by:jagguy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 40484588
The basics here: http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_201-Handling-date-and-time-in-PHP-and-MySQL.html

I'll give you a tested example in a moment, using strtotime() and date().
0
 
LVL 110

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 40484592
Please see: http://iconoun.com/demo/temp_jagguy.php

<?php // demo/temp_jagguy.php
ini_set('display_errors', TRUE);
ini_set('log_errors',     TRUE);
error_reporting(E_ALL);

// THE ARRAY OF TIME-COMPONENTS
$arr = array
( 'hour'     => '01'
, 'min'      => '00'
, 'meridian' => 'pm'
)
;

// THE GOAL: I need this to be 13:00:00

// CREATE A USABLE STRING WITH THE TIME IN IT
$str = 'TODAY ' . $arr['hour'] . ':' . $arr['min'] . ' ' . $arr['meridian'];

// REFORMAT TO GET 24-HOUR TIME
$new = date('H:i:s', strtotime($str));

// SHOW THE WORK PRODUCT
echo PHP_EOL . "$str == $new";

Open in new window

HTH, ~Ray
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question