Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP set date('w') function return Sunday as 7, instead of 0

Tags:

date

php

time

From official manual , the date ('w') shows the current date as

0 = Sunday
1 = Monday

.....

6 = Saturday

The problem is , without any further modification , are there any way (eg. set parameter?) to specific the Sunday as 7 instead of 0 ? thanks

like image 995
user1871516 Avatar asked Jun 06 '13 03:06

user1871516


People also ask

Which function is set date in PHP?

The PHP date() function is used to format a date and/or a time.

How can I get current date from next week in PHP?

just used it - date('Y-m-d H:i:s', strtotime('+1 week')); works fine in PHP 7 to give one week from now.

How does PHP date function work?

The date function in PHP is used to format the timestamp into a human desired format. The timestamp is the number of seconds between the current time and 1st January, 1970 00:00:00 GMT. It is also known as the UNIX timestamp. The default time zone can also be set programmatically using PHP scripts.


2 Answers

Try to use 'N' format specifier for date() function:

date('N')

Description: ISO-8601 numeric representation of the day of the week (added in PHP 5.1.0)

Example returned values: 1 (for Monday) through 7 (for Sunday)

like image 79
BlitZ Avatar answered Oct 14 '22 13:10

BlitZ


date('N')

N - The ISO-8601 numeric representation of a day (1 for Monday, 7 for Sunday)

like image 41
singh Avatar answered Oct 14 '22 13:10

singh