Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

covert time array to string

Posted on 2014-12-06
2
Medium Priority
?
144 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 111

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 111

Accepted Solution

by:
Ray Paseur earned 2000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Containers like Docker and Rocket are getting more popular every day. In my conversations with customers, they consistently ask what containers are and how they can use them in their environment. If you’re as curious as most people, read on. . .
By, Vadim Tkachenko. In this article we’ll look at ClickHouse on its one year anniversary.
The viewer will learn how to dynamically set the form action using jQuery.
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

670 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