[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

convert string date to time then subtract 15 mins

Posted on 2012-08-13
3
Medium Priority
?
663 Views
Last Modified: 2012-08-13
stored in the database are time intervals as strings (yea i know not the best way) and i need to convert them to a date, then subtract 15 mins from them to get the time in the past
the database consists of the following in varchar format:

8:00 AM, 8:15 AM, 8:30 AM, 8:45 AM, 9:00 PM and so on
select starttime from booking where booking_id = 1
returns
----
|starttime 
| 8:00 AM 
----

Open in new window

what i want to know is how to convert the starttime to 7:45 or to accommodate any string (in 15 min intervals)

starttime  is stored as a varchar(20)
8:00 AM, 8:15 AM, 8:30 AM, 8:45 AM, 9:00 PM and so on
0
Comment
Question by:Timothy Golden
  • 2
3 Comments
 
LVL 3

Author Comment

by:Timothy Golden
ID: 38289034
just to be clear
$starttime  = 8:00 AM
i want $new_starttime = 7:45 AM
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 38289206
0
 
LVL 111

Accepted Solution

by:
Ray Paseur earned 2000 total points
ID: 38289235
See http://www.laprbass.com/RAY_temp_luckynh.php

<?php // RAY_temp_luckynh.php
error_reporting(E_ALL);
date_default_timezone_set('America/Chicago');

/* PROBLEM DEFINITION
$starttime  = 8:00 AM
i want $new_starttime = 7:45 AM
*/ // END PROBLEM DEFINITION

$starttime = '8:00 AM';

$new = date('G:i A', strtotime('TODAY ' . $starttime . ' - 15 MINUTES'));
var_dump($new);

Open in new window

HTH, ~Ray
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
By, Vadim Tkachenko. In this article we’ll look at ClickHouse on its one year anniversary.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
Suggested Courses
Course of the Month19 days, 1 hour left to enroll

834 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