strtotime

What is a Unix timestamp and why use it?

断了今生、忘了曾经 提交于 2019-11-26 22:23:30
What is a Unix timestamp? In PHP, when working with dates, the function strtotime() outputs some integer value -- what is that? I tried to learn about this but I couldn't get satisfactory answer, especially why do we need to convert dates using strtotime() . What is a Unix Timestamp Simply put, the Unix timestamp is a way to track time as a running total of seconds. This count starts at the Unix Epoch on January 1st, 1970 at UTC. Therefore, the Unix timestamp is merely the number of seconds between a particular date and the Unix Epoch . It should also be pointed out that this point in time

Adding three months to a date in PHP

夙愿已清 提交于 2019-11-26 22:21:08
问题 I have a variable called $effectiveDate containing the date 2012-03-26 . I am trying to add three months to this date and have been unsuccessful at it. Here is what I have tried: $effectiveDate = strtotime("+3 months", strtotime($effectiveDate)); and $effectiveDate = strtotime(date("Y-m-d", strtotime($effectiveDate)) . "+3 months"); What am I doing wrong? Neither piece of code worked. 回答1: Change it to this will give you the expected format: $effectiveDate = date('Y-m-d', strtotime("+3 months

How to get previous month and year relative to today, using strtotime and date?

寵の児 提交于 2019-11-26 22:18:15
I need to get previous month and year, relative to current date. However, see following example. // Today is 2011-03-30 echo date('Y-m-d', strtotime('last month')); // Output: 2011-03-02 This behavior is understandable (to a certain point), due to different number of days in february and march, and code in example above is what I need, but works only 100% correctly for between 1st and 28th of each month. So, how to get last month AND year (think of date("Y-m") ) in the most elegant manner as possible, which works for every day of the year? Optimal solution will be based on strtotime argument

PHP's strtotime() in Java

梦想与她 提交于 2019-11-26 22:15:35
strtotime() in PHP can do the following transformations: Inputs: strtotime(’2004-02-12T15:19:21+00:00′); strtotime(’Thu, 21 Dec 2000 16:01:07 +0200′); strtotime(’Monday, January 1st’); strtotime(’tomorrow’); strtotime(’-1 week 2 days 4 hours 2 seconds’); Outputs: 2004-02-12 07:02:21 2000-12-21 06:12:07 2009-01-01 12:01:00 2009-02-12 12:02:00 2009-02-06 09:02:41 Is there an easy way to do this in java? Yes, this is a duplicate . However, the original question was not answered. I typically need the ability to query dates from the past. I want to give the user the ability to say 'I want all

php get microtime from date string

岁酱吖の 提交于 2019-11-26 22:03:02
问题 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

Getting first weekday in a month with strtotime

十年热恋 提交于 2019-11-26 21:48:15
问题 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

PHP Strtotime -1month -2month

流过昼夜 提交于 2019-11-26 21:16:19
问题 This was working fine yesterday with no changes to the code. echo date("M", strtotime("-3 month", time()) ); echo date("M", strtotime("-2 month", time()) ); echo date("M", strtotime("-1 month", time()) ); echo date("M", time()); The output it was producing yesterday was as you would expect- i.e. Apr, May, Jun, Jul Today it echoes May May Jul Jul Any ideas? Thanks in advance. 回答1: It might be related to bug #44073 You could try with something like this : echo date("M", strtotime("-3 month",

Getting all dates for Mondays and Tuesdays for the next year

为君一笑 提交于 2019-11-26 20:47:56
I need to output a list of dates (only Mondays and Tuesdays) for the next 12 months from current date like so: Jan 2010 Tue 12 Jan 2010 Mon 18 Jan 2010 Tue 19 Jan 2010 Mon 25 Jan 2010 Feb 2010 Tue 02 Feb 2010 Mon 08 Feb 2010 Tue 09 Feb 2010 Mon 15 Feb 2010 Tue 16 Feb 2010 Mon 22 Feb 2010 Mar 2010 Tue 09 Mar 2010 Mon 15 Mar 2010 Tue 16 Mar 2010 ... Being new to PHP I figured strtotime and looping over the next 52 weeks is the best way to go. $blockedDatesInput = "08 Mar 2010,12 Apr 2010"; // dont show these dates $blockedDates = explode ("," , $blockedDatesInput); // convert to array

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

丶灬走出姿态 提交于 2019-11-26 20:38:20
问题 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']));

PHP date showing '1970-01-01 ' after conversion

霸气de小男生 提交于 2019-11-26 19:19:52
问题 I have a form in which date format is dd/mm/yyyy . For searching database , I hanverted the date format to yyyy-mm-dd . But when I echo it, it showing 1970-01-01 . The PHP code is below: $date1 = $_REQUEST['date']; echo date('Y-m-d', strtotime($date1)); Why is it happening? How can I format it to yyyy-mm-dd ? 回答1: Replace / with - : $date1 = strtr($_REQUEST['date'], '/', '-'); echo date('Y-m-d', strtotime($date1)); 回答2: January 1, 1970 is the so called Unix epoch. It's the date where they