php - Convert date into timestamp where strtotime has already been used -


I am trying to convert to the timestamp on the date of the next 7 days so that I compare the database with my date timestamp

  $ next_date = date ("d / m / y", stratetime ("7 days"))   

Output

  30/04/2014   

Now I'm running strtotime () again on $ next_date variable which keeps the next 7days And changes the timestamp.

  echo strtotime ($ next_date);   

This is not working, I followed this reply and some others.

As an alternative suggestion, you should have PHP internal date time () And the dateInterwALL () classes makes it a little easier to convert between formats and does addition and subtraction to the emo. The date-interval requires at least PHP version 5.3.

Example:

  // Make Current Date Time $ currDate = New DateTime (); // Copy the existing datetime and add an interval of 7 days nextdate = clone $ currDate; $ Next day - & gt; Add (New Date Interval ('P7D')); // Both objects are easily converted into timestamps echo $ currDate-> GetTimestamp (); // Eg: 1398296728 echo $ next date-> GetTimestamp (); // eg: 1398901528 // and both can be easily formatted in other formats, $ currDate- & gt; Echo ('d / m / y'); // Eg: 24/04/2014 echo $ nextDate- & gt; Format ('D / M / Y'); // example: 01/05/2014   

edit

For completeness, here is another example that you have seven days How to add date time object:

  $ now = new date-time (); $ Then = $ now-> Modify ('+ 7 Days'); var_dump ($ Now-> Format ('Y-M-D'), $ then-> Format ('Y-M-D'));   

yield:

  string (10) "2016-05-24" string (10) "2016-05-31" / Pre> 

You can use DateTime - The difference in this case is that DateTime :: modify () will modify the example $ Now where will date back to the date Immutable :: modify () a new DateTimeImmutable object - so if you need to create a new object while retaining the old object , Then this is probably the most



  • Comments

    Popular posts from this blog

    Java - Error: no suitable method found for add(int, java.lang.String) -

    java - JPA TypedQuery: Parameter value element did not match expected type -

    c++ - static template member variable has internal linkage but is not defined -