convert string date to time then subtract 15 mins

Posted on 2012-08-13
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
| 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
Question by:luckynh
    LVL 3

    Author Comment

    just to be clear
    $starttime  = 8:00 AM
    i want $new_starttime = 7:45 AM
    LVL 107

    Expert Comment

    by:Ray Paseur
    LVL 107

    Accepted Solution


    <?php // RAY_temp_luckynh.php
    $starttime  = 8:00 AM
    i want $new_starttime = 7:45 AM
    $starttime = '8:00 AM';
    $new = date('G:i A', strtotime('TODAY ' . $starttime . ' - 15 MINUTES'));

    Open in new window

    HTH, ~Ray

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
    Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
    In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…
    This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

    732 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

    24 Experts available now in Live!

    Get 1:1 Help Now