Solved

covert time array to string

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

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 108

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
The viewer will learn how to dynamically set the form action using jQuery.

758 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now