Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

covert time array to string

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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

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. . .
In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

824 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