strtotime

How do I return the previous Sunday from 7 days ago using PHP date()?

别来无恙 提交于 2019-12-11 08:39:50
问题 Here is what I have so far: $date = date('Y-m-d h:i:s', strtotime('-7 days')); $start = date('Y-m-d h:i:s', strtotime($date,'previous Sunday')); When outputting $start, it returns: 1969-12-31 06:00:00 What am I doing wrong? 回答1: $date needs to e a timestamp $date = strtotime('-7 days'); $start = date('Y-m-d h:i:s', strtotime('previous Sunday',$date)); 回答2: You have the arguments the wrong way round: date('Y-m-d h:i:s', strtotime('previous Sunday', $date)); Edit : Furthermore, you have made

PHP strtotime giving wrong date with GMT conversion? [closed]

穿精又带淫゛_ 提交于 2019-12-11 07:12:28
问题 This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 6 years ago . I'm reading a Last-Modified header which as a string is "Mon, 21 May 2013 09:10:30 GMT" and trying to compare that to my local time() (New Zealand). But

I'm weird with strtotime behaviour

纵然是瞬间 提交于 2019-12-11 04:38:27
问题 I am getting the From date and To date using jquery datepicker plugin. The following is the output of POST. Array ( [fromDate] => 01/03/2012 [toDate] => 15/03/2012 [hdnDownload] => Download ) I am trying to convert this date format to another date format like this: echo'fromdate'.$fromDate = date("Y/n/j", strtotime($_POST['fromDate'])); echo'todate'.$toDate = date("Y/n/j", strtotime($_POST['toDate'])); It gives me the following output: fromdate: 2012-1-3 todate:1969-12-31 The fromDate is fine

PHP Strtotime erratic function

隐身守侯 提交于 2019-12-11 04:33:01
问题 The following code should take the fourth friday of February and the fourth friday of April and return it. $datei1 = date(strtotime('fourth friday', strtotime('february', strtotime(date('01-m-Y'))))); $datei2 = date(strtotime('fourth friday', strtotime('april', strtotime(date('01-m-Y'))))); Its working but taking the 5th friday of April not the fourth. I can only assume that it does not believe the first of April counts. Any ideas, Marvellous 回答1: Your code is very complicated for no reason.

Can we use PHP function strtotime in Mysql Query [closed]

别说谁变了你拦得住时间么 提交于 2019-12-11 03:43:33
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 5 years ago . I have the following MySQL syntax which gives me an error. I am aware that you cannot compare date variables directly, so I use strtotime to create a Unix timestamp to compare dates. Can you use the PHP strtotime function within a MySQL query? $result = select * from table where

strtotime() converts a non existing date to another date

风流意气都作罢 提交于 2019-12-11 02:48:56
问题 I am building a timestamp from the date, month and year values entered by users. Suppose that the user inputs some wrong values and the date is "31-02-2012" which does not exist, then I have to get a false return. But here its converting it to another date nearby. Precisely to: "02-03-2012".. I dont want this to happen.. $str = "31-02-2012"; echo date("d-m-Y",strtotime($str)); // Outputs 02-03-2012 Can anyone help? I dont want a timestamp to be returned if the date is not original. 回答1: That

PHP: strtotime returns “nothing” of type “boolean”

依然范特西╮ 提交于 2019-12-10 17:16:47
问题 I have the variable $EDate , I used strtotime function with this variable with different values and the result was as following: $EDate = 10-21-2013; echo "strtotime($EDate)"; the result = nothing and the type is boolean $EDate = 09-02-2013; echo "strtotime($EDate)"; the result = 1360386000 and the type is integer $EDate = 09-30-2013; echo "strtotime($EDate)"; the result = nothing and the type is boolean $EDate = 09-30-2013; echo "strtotime($EDate)"; the result = nothing and the type is

PHP : strtotime() returns always 01/01/1970

╄→гoц情女王★ 提交于 2019-12-10 13:48:02
问题 I am trying to display dates in the European format (dd/mm/yyyy) with strtotime but it always returns 01/01/1970. Here is my codeline : echo "<p><h6>".date('d/m/Y', strtotime($row['DMT_DATE_DOCUMENT']))."</h6></p>"; In my database, the field is a varchar and records are formated like yyyy.mm.dd I use the same codeline for another field that is formated like yyyy-mm-dd (varchar too) and it works fine. Thanks for your help. 回答1: Since the format yyyy-mm-dd works, try to replace . with - : date(

strtotime not working with mm-dd-yyyy

ⅰ亾dé卋堺 提交于 2019-12-10 11:54:46
问题 I have a script which is fed dates in numerous different formats. I want to save these dates as timestamps so they can easily be manipulated/ordered. When i try an convert a mm-dd-yyyy type date to a timestamp, it fails. When the script runs, it does not know what format it will be fed, and as such this cannot be specified. Near all other formats of date seem to be converted fine. Could anyone advise how to fix this, or alternatively an alternative way that all date formats can be converted

force php strtotime to use UTC

佐手、 提交于 2019-12-09 15:14:27
问题 I've seen a few questions about this but not a clear answer... strtotime() will use the default timezone set for PHP when converting the string to a unix timestamp. However, I want to convert a string to unix timestamp in UTC. Since there is no parameter for doing so, how can this be done? The string I'm trying to convert is: 2011-10-27T20:23:39, which is already in UTC. I want to represent that as a unix timestamp also in UTC. Thank you 回答1: Set the system default timezone before making the