PHP - Last Saturday at 6pm [duplicate] - php

This question already has answers here:
PHP Date Function Seven days previous
(3 answers)
Closed 8 years ago.
I have a query where I want to pass in two variables and I feel like I am almost there but need a bit of guidance.
I have a cron job set up to run at 6pm every Saturday that will select tickets for the last week.
Select tickets that are between 6pm last saturday and 5:59 today bearing in mind that this willl be run at 6pm every saturday.
I'm looking for help to create two variables.
6pm last Saturday
5:59pm today
Have looked at strtotime and date but can't see anything that would fit?

Check strtotime:
$time = strtotime("last Saturday 6 PM");
echo date("Y-m-d H:i:s", $time);

A mysql solution could be:
SELECT *
FROM tickets
WHERE
ticket_datetime BETWEEN
DATE_SUB(CONCAT(DATE(NOW()),' 06:00:00'), INTERVAL 1 WEEK)
AND
CONCAT(DATE(NOW()),' 06:00:00')

Related

Get next 2 days not counting current day in PHP [duplicate]

This question already has answers here:
PHP Strtotime without current time?
(2 answers)
Closed 4 months ago.
I have an Unix timestamp like this 1660293621 (2022-08-12 8:40). I want to get next 2 days not counting current date. I expect the result to be 2022-08-15 00:00.
I tried
strtotime("+3 Days", $current_date)
but it returns 2022-08-15 8:40, not 00:00
How can I get that in PHP? Thank you~
$Today=date('y:m:d');
// add 3 days to date
$NewDate=Date('y:m:d', strtotime('+3 days'));
Reference:
Increase days to php current Date()
I figured it out, just add 0:00 will help
$next2days = strtotime("+3 days 0:00", $current_date);

How to get the day of the week in DateTime? [duplicate]

This question already has answers here:
How to find the date of a day of the week from a date using PHP?
(9 answers)
Closed 3 years ago.
How to get the day of the week in DateTime ?
I can’t find the way to get the day of the week from a DateTime.
It’s can be number or string, both are ok.
$today = new DateTime("today");
echo $ today->//whatever to get Friday, Monday or 5, 0
How to get the day of the week in DateTime ?
Edit:
I am using DateTime, not date.
You can use format() function
$today->format('l') //Sunday through Saturday
$today->format('w') //0 (for Sunday) through 6 (for Saturday)

Create last day of month PHP [duplicate]

This question already has answers here:
How to find the last day of the month from date?
(30 answers)
Closed 7 years ago.
I have a form with a date picker which allows the user to select only the month and year.
Upon submitting the form The value it gets from the form is:
$the_Date = $_POST['month_Year'];
echo 'month date: '.$the_Date.'<br />';
// echos 'month date: July 2015' in this example
I need to use this to create 2 dates. I need the 1st of July and the 31st of July.
I can create the 1st no problems using:
$first_Of_Month = date("Y-m-d",strtotime('1 '.$the_Date));
But I don't know how to create the $last_Of_Month seeing as not all months end on the 31st. Any help would be greatly appreciated
When using date(), the value t returns the number of days in the month.
You can run $last_of_month = date("Y-m-t", strtotime($the_Date));

calculating calendar week php [duplicate]

This question already has an answer here:
Week number and Week day
(1 answer)
Closed 9 years ago.
If anyone has an idea how can I calculate a calendar week depending on given date in php, for example 06.06.2013 (format like this 2013-06-06). is calendar week 23. I was searching for the solution all morning and found nothing useful. Any help or link, anything would be appreciated. Thank you
Use date("W")
echo date("W", strtotime('2013-06-06'));
See it in action
date('W') should give you the week of the year. RTM
If you don't have your time as a unix timestamp you can use strtotime() first and pass it as the second parameter
ex. date('W',strtotime($my_time_string))
You can see the PHP manual here
Like this:
$time = '2013-06-06';
$calendar_week = date('W', strtotime($time));

PHP get the date of this weeks monday [duplicate]

This question already has answers here:
Get first day of week in PHP?
(39 answers)
Closed 9 years ago.
Any way to take a date like this 2013-05-29 in PHP and get the date (in the same format) of that weeks monday? So the output would be like this: 2013-05-27
date('Y-m-d', strtotime('last sunday +1 day', strtotime('2013-05-29')));
last sunday +1 day because last monday would return the Monday of the previous week if $timestamp actually was a Monday already.
And parsing of the original date value 2013-05-29 in a second step because all together as one argument does not work well (mixing of absolute and relative date values is something strtotime does not like very much).

Categories