Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > PHP How-To
|
PHP How-To Post your "How do I do this with PHP?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 16th, 2008, 04:13 PM
Authorized User
 
Join Date: Nov 2007
Posts: 54
Thanks: 1
Thanked 0 Times in 0 Posts
Default writing time of a day

I am trying to create a specific time on a specific date. For example, 09:00 on October 31, 2008.
The problem: I have a specific date and time say 23:00, Oct 31, 2008 stored as a string. I want to set time to 09:00.
I have tried using date_parse, and mktime to do the job but they are giving me strange outputs as 1969-12-31 19:00:00, it should be 2008-10-16 17:00:00.
If I break the function down (using strtotime), I can see the correct hours, min, sec, month, day, and year. It is hard to understand that if I pass on these to mktime or use date_parse, the functions are giving me wrong output.
variable storing date = string(19) "2008-10-31 23:00:00"
I get the right month, day, year, hours, min, sec if I use date and strtotime. Why am I getting wrong output with date_parse and mktime?
Can anyone offer a hand ?


 
Old December 17th, 2008, 06:51 PM
Registered User
 
Join Date: Dec 2008
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

"23:00, Oct 31, 2008" is not a nice date time format, still there's maybe a solution:
PHP Code:
<?php
function ChangeTime($olddatetime = array(), $newtime "" ){
    
$ArrDatetime Explode(",",$olddatetime);
    
$ArrDatetime[0] = $newtime;
    return 
implode(",",$ArrDatetime);
}

//function test
echo ChangeTime("23:00, Oct 31, 2008","09:00");
?>
Good luck!





Similar Threads
Thread Thread Starter Forum Replies Last Post
getting the same day of the week. crabjoe Classic ASP Basics 3 February 27th, 2008 12:45 PM
time zone & day light time rajn ASP.NET 1.0 and 1.1 Professional 0 August 7th, 2007 05:02 PM
DAY of the week wdepreter Excel VBA 3 February 7th, 2007 06:44 AM
how to get the day from a given date pherms Classic ASP Basics 2 April 16th, 2004 05:38 PM
day to day use of XML mano XML 1 November 27th, 2003 01:39 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.