Re: [PHP] Date manipulation
On Thu, Oct 25, 2012 at 3:06 PM, Ron Piggott ron.pigg...@actsministries.org wrote: Is it possible for PHP to accept the following as a date: 04:11:22 Aug 21, 2011 PDT so I may output it as: gmdate(‘Y-m-d H:i:s’) - I want the time zone included Sure. ?php $ds = strtotime('04:11:22 Aug 21, 2011 PDT'); echo gmdate('Y-m-d H:i:s',$ds); ? -- /Daniel P. Brown Network Infrastructure Manager http://www.php.net/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Date Manipulation
In addition to Matthew's response... Strtotime() and mktime() both return a serial date. That's the 1101945775 number you got. To get this back to a mmdd format that you seem to be trying to do with mktime(), you want to use date() as Matthew suggested. Again, I think examples help more than RTFM: date(Ymd,strtotime(now)); mktime() and strtotime() produce the same output which is not a human-readable date format. So basically, in your example below, you told it that you wanted: The serial date (mktime()) of hour Ymd (evaluates as 0 I believe), minute 1101945775, with seconds, month, day and year all empty. I think the leaving them empty is ok since they're optional from right to left, and the excessive number of minutes probably wouldn't be a big deal (unless it goes past the maximum date rate, which looks like what it's doing). Let's do a quick calc: Looks like the max number that mktime() can produce is: 2147483647 This is 1/18/2038 22:14:07 If you take your serial date 1101945775 and pipe it into the minutes section of mktime(), it'll produce that number times 60 (60 seconds in a minute) and try to get that date. This produces a number: 66116746500 Significantly bigger than the max serial date for Windows mentioned above. Long answer to maybe help you understand how it all works. Btw: The serial date is the number of seconds since the beginning of the Unix Epoch (# of secs since January 1, 1970 that is... Hey, time's gotta start somewhere eh?) Hope this helps clarify mktime(), strtotime() and date(). -TG -Original Message- From: Christopher Weaver [mailto:[EMAIL PROTECTED] Sent: Wednesday, December 01, 2004 7:13 PM To: [EMAIL PROTECTED] Subject: Re: [PHP] Date Manipulation This code: echo strtotime(now); echo mktime(Ymd, strtotime(now)); is producing this result: 1101945775 Warning: mktime(): Windows does not support negative values for this function ... -1 What am I doing wrong? Thanks again. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Date Manipulation
As was already mentioned, mktime() and strtotime() both return a serial date. I use mktime() a lot to add/subtract days and such. It automatically compensates for leap days and all that. Example: ?php $month = 1; $day = 31; $year = 2004; $serialdate = mktime(0,0,0,$month,$day + 1,$year); echo date(m/d/Y, $serialdate); ? This should output 2/1/2004 (unless I made a typo). The initial 0,0,0 are the hour, minute, second. It works equally well with any numbers you give it for any of those values and if you throw it back into the date() function, you can format the outputted date however you want. I know mktime and strtotime were already mentioned, but I think examples help too so pardon me for expanding on it. -TG -Original Message- From: Christopher Weaver [mailto:[EMAIL PROTECTED] Sent: Tuesday, November 30, 2004 9:19 PM To: [EMAIL PROTECTED] Subject: [PHP] Date Manipulation I've looked at the date functions in the manual but can't find what I need. All I want to do is add and subtract days without ending up with bogus date values. IOW, Nov. 29 + 7 days shouldn't be Nov. 36. Just a nod in the write direction would be great. Thanks. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Date Manipulation
This code: echo strtotime(now); echo mktime(Ymd, strtotime(now)); is producing this result: 1101945775 Warning: mktime(): Windows does not support negative values for this function ... -1 What am I doing wrong? Thanks again. John Holmes [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Christopher Weaver wrote: I've looked at the date functions in the manual but can't find what I need. All I want to do is add and subtract days without ending up with bogus date values. IOW, Nov. 29 + 7 days shouldn't be Nov. 36. Just a nod in the write direction would be great. mktime() or strtotime() -- ---John Holmes... Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/ php|architect: The Magazine for PHP Professionals www.phparch.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Date Manipulation
* Christopher Weaver [EMAIL PROTECTED]: This code: echo strtotime(now); echo mktime(Ymd, strtotime(now)); is producing this result: 1101945775 Warning: mktime(): Windows does not support negative values for this function ... -1 What am I doing wrong? Using the wrong function, or providing the wrong arguments. From the arguments you're giving mktime, I suspect you actually want date(), which would yield a string in the format 'YYYMMDD'. However, if you really want to use mktime, you should be be using it as follows: int mktime ( [int $hour], [int $minute], [int $second], [int $month], [int $day], [int $year], [int $is_dst] ) Please read the manual entries for the functions you're using before posting to the list. John Holmes [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Christopher Weaver wrote: I've looked at the date functions in the manual but can't find what I need. All I want to do is add and subtract days without ending up with bogus date values. IOW, Nov. 29 + 7 days shouldn't be Nov. 36. Just a nod in the write direction would be great. mktime() or strtotime() -- Matthew Weier O'Phinney | mailto:[EMAIL PROTECTED] Webmaster and IT Specialist | http://www.garden.org National Gardening Association| http://www.kidsgardening.com 802-863-5251 x156 | http://nationalgardenmonth.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Date Manipulation
Sorry about that. Works great with date. Thanks. Matthew Weier O'Phinney [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] * Christopher Weaver [EMAIL PROTECTED]: This code: echo strtotime(now); echo mktime(Ymd, strtotime(now)); is producing this result: 1101945775 Warning: mktime(): Windows does not support negative values for this function ... -1 What am I doing wrong? Using the wrong function, or providing the wrong arguments. From the arguments you're giving mktime, I suspect you actually want date(), which would yield a string in the format 'YYYMMDD'. However, if you really want to use mktime, you should be be using it as follows: int mktime ( [int $hour], [int $minute], [int $second], [int $month], [int $day], [int $year], [int $is_dst] ) Please read the manual entries for the functions you're using before posting to the list. John Holmes [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Christopher Weaver wrote: I've looked at the date functions in the manual but can't find what I need. All I want to do is add and subtract days without ending up with bogus date values. IOW, Nov. 29 + 7 days shouldn't be Nov. 36. Just a nod in the write direction would be great. mktime() or strtotime() -- Matthew Weier O'Phinney | mailto:[EMAIL PROTECTED] Webmaster and IT Specialist | http://www.garden.org National Gardening Association| http://www.kidsgardening.com 802-863-5251 x156 | http://nationalgardenmonth.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Date Manipulation
Christopher Weaver wrote: I've looked at the date functions in the manual but can't find what I need. All I want to do is add and subtract days without ending up with bogus date values. IOW, Nov. 29 + 7 days shouldn't be Nov. 36. Just a nod in the write direction would be great. mktime() or strtotime() -- ---John Holmes... Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/ php|architect: The Magazine for PHP Professionals www.phparch.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php