strtotime

strtotime on incorrect dates

强颜欢笑 提交于 2019-11-28 08:16:50
问题 I found something odd about strtotime(). On dates that do not exist it returns the day after. $d30= strtotime("2017-06-30"); Echo $d30 ."\n"; Echo date("Y-m-d", $d30)."\n\n"; // 2017-06-30 $d31= strtotime("2017-06-31"); Echo $d31 ."\n"; Echo date("Y-m-d", $d31)."\n\n"; // 2017-07-01 $d32= strtotime("2017-06-32"); Echo $d32 ."\n"; Echo date("Y-m-d", $d32); // 1970-01-01 https://3v4l.org/AjMAE I understand the last one. It returns nothing as it's an error. But why does the second one return

date() method, “A non well formed numeric value encountered” does not want to format a date passed in $_POST

浪子不回头ぞ 提交于 2019-11-28 08:13:48
I unfortunately can't use DateTime() as the server this project is on is running PHP v.5.2. the line in question: $aptnDate2 = date('Y-m-d', $_POST['nextAppointmentDate']); throws the following error: Notice: A non well formed numeric value encountered so I var dump to make sure it's well formatted.. var_dump($_POST['nextAppointmentDate']); string(10) "12-16-2013" The php docs state that it takes a timestamp not a string. but when I do: date('Y-m-d', strtotime($_POST['nextAppointmentDate'])); and then var_dump the result, I get this: string(10) "1969-12-31" why can I not format a date with

Removing exactly one month from a date

时光怂恿深爱的人放手 提交于 2019-11-28 06:29:10
问题 It seems that you can't use strotime if you need reliable and accurate date manipulation. For example, if the month has 31 days, then it appears that strtotime simply minuses 30 days, not a whole month. So, for example, if $event["EndDate"] is equal to "2013-10-31 00:00:01", the following code: echo date("Y/n/j", strtotime('-1 month', strtotime($event["EndDate"])); Ouputs: 2013/10/1 instead of 2013/09/30 . QUESTION: Now how I know how NOT to do it, is there another, more accurate, way to make

php string in a date format, add 12 hours

佐手、 提交于 2019-11-28 04:16:46
问题 I have this string object in my php array "2013-03-05 00:00:00+00" I would like to add 12 hours to the entry within PHP, then save it back to string in the same format I believe this involves converting the string to a date object. But I'm not sure how smart the date object is and if I need to tell it formatting parameters or if it is supposed to just take the string $date = new DateTime("2013-03-05 00:00:00+00"); $date->add("+12 hours"); //then convert back to string or just assign it to a

adding 30 minutes to datetime php/mysql

故事扮演 提交于 2019-11-28 04:05:16
I have a datetime field (endTime) in mysql. I use gmdate() to populate this endTime field. The value stored is something like 2009-09-17 04:10:48. I want to add 30 minutes to this endtime and compare it with current time. ie) the user is allowed to do a certain task only 30 minutes within his endTime. After 30 minutes of his endTime, i should not allow him to do a task. how can i do that in php? i'm using gmdate to make sure there are no zone differences. Thanks in advance RageZ If you are using MySQL you can do it like this: SELECT '2008-12-31 23:59:59' + INTERVAL 30 MINUTE; For a pure PHP

php get microtime from date string

血红的双手。 提交于 2019-11-28 01:48:39
I am trying to get the time passed between two datetime strings (including milliseconds) example: $pageTime = strtotime("2012-04-23T16:08:14.9-05:00"); $rowTime = strtotime("2012-04-23T16:08:16.1-05:00"); $timePassed = $rowTime - $pageTime; echo $timePassed . "<br/><br/>"; What I want to see echoed is "1.2" but strtotime() ignores the millisecond part of the string. Also, apparently microtime() doesn't let you give it a datestring... Is there an alternative function for calculating this, or am I going to have to do some string parsing to extract the seconds and milliseconds and subtract? Try

PHP - using date to find out daylight savings time

丶灬走出姿态 提交于 2019-11-28 01:21:32
问题 I want to give date() a date and have it return if that date is DST or not. Running PHP 5.4.7 via xampp on a windows 7 box. A linux box running PHP 5.2.8 returns 0 no matter what date I give it. What's wrong with my code? echo date('I', strtotime('30-Mar-2013')); # should return a 1 but returns 0 echo date('I', strtotime('30-Mar-2013 America/Los_Angeles'))."<br>"; # returns 0 echo date('I', strtotime('31-Mar-2013 America/Los_Angeles'))."<br>"; # returns 1 The switch between DST should be

PHP get next occurrence of Monday from a certain date (with time)

核能气质少年 提交于 2019-11-28 01:00:46
问题 I'm looking for the next Thursday after a specific date, say 2014-02-25 . The problem I'm having here is that when I use the below code, the time seems to be erased. <?php $timestamp = '2014-02-25 10:30:00'; echo date('Y-m-d H:i:s', strtotime("next Thursday", strtotime($timestamp))); ?> The result I am getting is 2014-02-27 00:00:00 when I would like it to be 2014-02-27 10:30:00 Is there something I am missing here that is causing the time to be set to midnight? I appreciate the help, thanks.

Getting first weekday in a month with strtotime

淺唱寂寞╮ 提交于 2019-11-28 00:54:24
I'm trying to figure out the first wednesday of a given month using strtotime , but the "first wednesday" argument fails whenever the first wednesday happens to fall on the 1st. For a more general illustration of this problem, see the following code and result: $mon = strtotime("December 2010 first monday"); $tue = strtotime("December 2010 first tuesday"); $wed = strtotime("December 2010 first wednesday"); $thu = strtotime("December 2010 first thursday"); $fri = strtotime("December 2010 first friday"); $sat = strtotime("December 2010 first saturday"); $sun = strtotime("December 2010 first

strtotime equivalent in .NET

醉酒当歌 提交于 2019-11-27 23:20:12
Is there an equivalent of PHP's strtotime() function working on .NET Framework. I'm talking about it's capacity to handle strings likes: strtotime(" now ") strtotime("10 September 2000") strtotime(" +1 day ") strtotime(" +1 week ") strtotime(" +1 week 2 days 4 hours 2 seconds ") strtotime(" next Thursday ") strtotime(" last Monday ") Obviously DateTime.Parse() and Convert.ToDateTime() don't do that. The closest I've found is a small class which only handles a few of those: http://refactormycode.com/codes/488-parse-relative-date EDIT: I'm not interested in C# compile-time features. The problem