How can get first and last day of current week in PHP?

How can get first and last day of current week in PHP?

$monday = date(‘d-m-Y’,strtotime(‘last monday’,strtotime(‘next monday’,strtotime($date)))); You have to get next monday first then get the ‘last monday’ of next monday. So if the given date is monday it will return the same date not last week monday.

How do I get the start of the week in PHP?

Use strtotime() function to get the first day of week using PHP. This function returns the default time variable timestamp and then use date() function to convert timestamp date into understandable date. strtotime() Function: The strtotime() function returns the result in timestamp by parsing the time string.

How do you get the first day of the month in PHP?

php $dt = “2008-02-23”; echo ‘First day : ‘. date(“Y-m-01”, strtotime($dt)).

How do you change Monday to the first day of the week in SQL?

Option 2: Monday as the First Day of the Week SELECT DATEADD(week, DATEDIFF(week, 0, RegistrationDate – 1), 0) AS Monday; In the expression above, we add the specified number of weeks to the 0 date.

How can I get last month start and end in php?

$date = strtotime ( $datestring ); // Last date of current month. $day = date ( “l” , $lastdate );

What is the first day of the week in Philippines?

For most observant adherents of Christianity, Sunday is generally observed as a day of worship and rest, recognising it as the Lord’s Day and the day of Christ’s resurrection; in the United States, Canada, China, Japan, the Philippines as well as in South America, Sunday is the first day of the week.

How do I get the first day of the current week in SQL Server?

In SQL Server, there is a @@DATEFIRST function, which returns the current week start day (value of SET DATEFIRST).

How do I set the first day of the week in SQL?

The DATEFIRST statement sets the first day of the week for the session to a number from 1 through 7. To change the DATEFIRST setting for a session without changing the language setting, use the SET DATEFIRST command.

How do I get the first day of the week in PHP?

function firstDayOfWeek ($date) { $day = DateTime::createFromFormat (‘m-d-Y’, $date); $day->setISODate ( (int)$day->format (‘o’), (int)$day->format (‘W’), 1); return $day->format (‘m-d-Y’); } var_dump (firstDayOfWeek (’06-13-2013′)); This will deal with year boundaries and leap years.

What is the difference between $weekstart and $weekstop in PHP?

strtotime is faster than new DateTime ()->getTimestamp ().

Is it possible to create a calendar using PHP datetime?

Show activity on this post. The DateTime class in PHP (5.3+) works just great as long as the first day of the week in your country is Sunday. In the Netherlands the first day of the week is Monday and that just makes the class useless for building a calendar with week view and calculations.

How to get first day (Monday) of current week?

The easiest way to get first day (Monday) of current week is: strtotime (“next Monday”) – 604800; where 604800 – is count of seconds in 1 week (60*60*24*7). This code get next Monday and decrease it for 1 week. This code will work well in any day of week. Even if today is Monday.

Related Post