Asked  7 Months ago    Answers:  5   Viewed   26 times

first let me show you my code:

$lastWeek = date('m-d-Y', strtotime('-1 week'));

That's how to get the timestamp from last week. Is there a chance I gan get the timestamp from last saturday?

I hope you know what I mean.

Thanks a lot.

 Answers

84

What's wrong with

$last_sat = strtotime("last Saturday"); 

EDIT

The time should be set to '00:00:00';

echo date('d-M-Y H:i:s',$last_sat);

gives

29-Jan-2011 00:00:00
Wednesday, March 31, 2021
 
Ultimater
answered 7 Months ago
96

You could also take a look at the DatePeriod class:

$period = new DatePeriod(
     new DateTime('2010-10-01'),
     new DateInterval('P1D'),
     new DateTime('2010-10-05')
);

Which should get you an array with DateTime objects.

To iterate

foreach ($period as $key => $value) {
    //$value->format('Y-m-d')       
}
Wednesday, March 31, 2021
 
CAMason
answered 7 Months ago
24

You need to call DateInterval::format() to display that difference as a string.

echo $diff->format('%d days');

See the manual for all of the available formatting options.

Wednesday, July 7, 2021
 
mattltm
answered 4 Months ago
41

use SimpleDateFormat, see tutorial here. But it's not recommended this approach, if you save it as a long, you can compare it, order, etc...

Saturday, August 21, 2021
 
Aniket Thakur
answered 2 Months ago
75

That's currently not possible with the Telegram Bot API.

Thursday, October 14, 2021
 
Kevin
answered 1 Week ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :