time() Function php

Asked

Viewed 104 times

1

I am paying for some purchases that have specific dates, and when I step as parameter a date should be < that date("Y-m-t", time() + 14*24*60*60), that in case it would have to be 2 weeks, it page me 1 month. According to the php doc, 24*60*60 is 1 day soon date("Y-m-t", time() + 14*24*60*60) would be 14 days/ 2 weeks. Anyone understand why this?

  • From the current date you want to add 14 more days?

  • Yeah, I need to get today’s date 14 more days, then 1 more month, then 2 more months..

  • Do the answers solve this? Or is something missing?

  • one more question, on strtotime when I want more than a week, or month, I have to put in plural? 2 Weeks, 2 months ?

  • can be in the singular, whatever.

  • so that’s it. All my doubts have been solved. Thank you to everyone.

  • :D always come back!

Show 2 more comments

2 answers

2


If you only want to use functions, strftime() and strtotime() also solve.

echo strftime('%Y-%m-%d', strtotime('+2 weeks'));
  • Thank you very much, it worked perfectly.

1

Instead of using the date() you can use DateTime which has several interesting methods.

Doc PHP - Datetime

Using the method add() - Doc Datetime - Add

Example:

$now = new DateTime();

echo $now->format('d/m/Y H:i:s'); // exibe 18/09/2015 10:12:40

echo '<br />';

$now->add(new DateInterval('P2W')); 

echo $now->format('d/m/Y H:i:s'); // exibe 02/10/2015 10:12:40

Browser other questions tagged

You are not signed in. Login or sign up in order to post.