strtotime

PHP strtotime() different results of monday this week

我的梦境 提交于 2019-12-05 04:40:28
I have a problem getting the date of monday in the current week. echo date('Y-m-d',strtotime('monday this week')); When I'm running the above code on my local machine (PHP 5.3) it outputs correctly '2011-03-07', but the same code on my server (PHP 5.2) outputs '2011-03-14' (that's monday next week). I've tried to run date('W') on both machines and I get the same result (10). Edit: Any ideas how get this work correctly? Thanks in advance. Not that I've seen exactly this problem, but I've seen ones very similar. strtotime seems to change behaviour between different versions of PHP, and barring

Adding days to specific day

自闭症网瘾萝莉.ら 提交于 2019-12-04 16:37:55
问题 Many examples are about adding days to this day. But how to do it, if I have different starding day? For example (Does not work): $day='2010-01-23'; // add 7 days to the date above $NewDate= Date('$day', strtotime("+7 days")); echo $NewDate; Example above does not work. How should I change the starding day by putting something else in the place of Date? 回答1: For a very basic fix based on your code: $day='2010-01-23'; // add 7 days to the date above $NewDate = date('Y-m-d', strtotime($day . "

php strtotime reverse

蹲街弑〆低调 提交于 2019-12-04 12:12:09
问题 Is there some function timetostr in php that will output today/tomorrow/next sunday/etc. from a given timestamp? So that timetostr(strtotime(x))=x 回答1: This might be useful for people coming here. /** * Format a timestamp to display its age (5 days ago, in 3 days, etc.). * * @param int $timestamp * @param int $now * @return string */ function timetostr($timestamp, $now = null) { $age = ($now ?: time()) - $timestamp; $future = ($age < 0); $age = abs($age); $age = (int)($age / 60); // minutes

PHP strtotime() function that accepts a format?

跟風遠走 提交于 2019-12-04 11:40:30
问题 strtotime() in PHP works great if you can provide it with a date format it understands and can convert, but for example you give it a UK date it fails to give the correct unix timestamp. Is there any PHP function, official or unofficial, that can accept a format variable that tells the function in which format the date and time is being passed? The closest I have come to doing this is a mixture of date_parse_from_format() and mktime() // Example usage of the function I'm after //Like the date

How to calculate the the interval between 2 unix timestamps in php WITHOUT dividing by 86400 (60*60*24)

为君一笑 提交于 2019-12-04 10:51:33
I have 2 unix timestamps, Im in AsiaPacific/Auckland timezone (GMT+12, DaylightSavings = GMT+13) I want to calculate the number of days interval between 2 timestamps, where one is inside daylight savings time and one is not. My example dates are 7 Feb 2009 (1233925200) to 21 September 2010 (1284985360) (not including 21st) see here it says 591 days: http://www.timeanddate.com/date/durationresult.html?d1=7&m1=2&y1=2009&d2=21&m2=9&y2=2010 Lets calculate, here are my timestamps (both are based on Auckland 00:00 time) 1284985360-1233925200 = 51060160 51060160 / 86400 = 590.974 So yea I need 591. I

PHP strtotime() “first monday february” returns second monday if february 1st is a monday

被刻印的时光 ゝ 提交于 2019-12-04 03:22:34
问题 I'm working on a PHP function which calculates holidays: function holidays($country = 1, $timespan_start = 0, $timespan_end = 0) The holidays are returned as timestamps in an array. Since I have to calculate dates like the first Monday of February, I tried strtotime("first monday february $year") and I've discovered that this does not work for 2010, since 02/01/2010 is a Monday - I get February 8th instead. This bug is actually mentioned in the change log: In PHP 5 prior to 5.2.7, requesting

php date less than another date

为君一笑 提交于 2019-12-04 03:10:32
given this kind of date object date("m/d/Y", strtotime($numerical." ".$day." of ".date("F"))) where it may give a mm/dd/yyyy day that is the "first Monday of August", for instance how can I decide if this date is greater than, less than, or equal to today's date? I need a now() method that works in this format and can be compared between date objects I haven't tried date() < date() , yet. But I don't think that will work any insight appreciated Compare the timestamps: if (strtotime($numerical." ".$day." of ".date("F")) < time()) { // older } else { // newer } This is possible as strtotime()

PHP获取当前时间、时间戳的各种格式写法汇总[日期时间]

夙愿已清 提交于 2019-12-04 02:21:39
今天写下php中,如何通过各种方法 获取当前系统时间、时间戳,并备注各种格式的含义,可灵活变通。 1、获取当前时间方法date() 很简单,这就是获取时间的方法,格式为:date($format, $timestamp),format为格式、timestamp为时间戳--可填参数。 2、获取时间戳方法time()、strtotime() 这两个方法,都可以获取php中unix时间戳,time()为直接获取得到,strtotime($time, $now)为将时间格式转为时间戳,$time为必填。清楚了这个,想了解更多,请继续往下看。 3、 date($format)用法 比如: echo date('Y-m-d') ,输出结果:2012-03-22 echo date('Y-m-d H:i:s'),输出结果:2012-03-22 23:00:00 echo date('Y-m-d', time()),输出结果:2012-03-22 23:00:00(结果同上,只是多了一个 时间戳 参数) (时间戳转换为日期格式的方法) echo date('Y').'年'.date('m').'月'.date('d').'日',输出结果:2012年3月22日 举例就这几个,只是格式的变通而已,下面是格式中各个字母的含义: /**************格式中可使用字母的含义************

strtotime result makes no sense, php bug?

旧城冷巷雨未停 提交于 2019-12-03 22:19:24
The following line: echo date('d', strtotime('First Saturday August 2015')); prints 08 , which doesn't seem to make any sense because the first occurrence of a day of the week can't be after the 7th. Is it a php bug or a php bug or maybe even a php bug? I don't know... php version: 5.5.19 Update #1: explained below the big difference that a simple word like " of " makes, after I investigated a little in the PHP source code. Update #2: There actually is a documentation page on PHP manual that explains the formats of dates accepted by strftime() . I just was not aware of it until now. Thanks

Using FQL to retrieve only upcoming birthdays from Facebook API

回眸只為那壹抹淺笑 提交于 2019-12-03 20:47:30
Using the information on FQL and the user table from Facebook's Developer's docs, I've come up with the following code. //build fql string $fql = "SELECT name, birthday_date FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me()) AND strlen(birthday_date) != 0 AND substr(birthday_date,0,3) IN ('{$currentMonth}/', '{$nextMonth}/')"; $fql.=$orderBy; $fql.=" LIMIT " . $limit; //query facebook $params = array( 'method' => 'fql.query', 'query' => $fql, 'callback' => '' ); $birthdays = $this->facebook_obj->api($params); $currentMonth and $nextMonth are set to string representations of the