Solved

covert time array to string

Posted on 2014-12-06
2
133 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

Technology Partners: 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

Suggested Solutions

Title # Comments Views Activity
PHP - How to insert data using sqlsrv on stored procedure? 8 54
SQL Procedure 7 43
Code not executing correctly. 3 40
Ajax success not firing alert 6 34
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
This article discusses how to create an extensible mechanism for linked drop downs.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

740 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