Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

day of the week to day number (Monday = 1, Tuesday = 2)

Tags:

date

php

datetime

Does php have a function to automatically convert dates to their day value, where Monday=1, Tuesday=2, etc. Something like this

$daynum = func('wednesday'); //echos 3 
like image 757
zmol Avatar asked Feb 10 '11 19:02

zmol


People also ask

What is the Excel formula for day of week?

Type the formula: =TEXT(A2,”ddd”) if you want the shortened version of the day or =TEXT(A2,”dddd”) if you want the full version of the days. Press the Return key. This should display the day of the week in our required format.

What are the 7 days names?

In English, the names are Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, and Sunday, then returning to Monday. Such a week may be called a planetary week.

How do you find the day of the week from a date?

Go to the Number tab in the Format Cells dialog box. Select Custom as the Category. Add dddd into the Type field for the full weekday name or ddd for the abbreviated weekday name. Press the OK button.


2 Answers

The date function can return this if you specify the format correctly:

$daynum = date("w", strtotime("wednesday")); 

will return 0 for Sunday through to 6 for Saturday.

An alternative format is:

$daynum = date("N", strtotime("wednesday")); 

which will return 1 for Monday through to 7 for Sunday (this is the ISO-8601 represensation).

like image 22
adrianbanks Avatar answered Sep 29 '22 07:09

adrianbanks


$day_of_week = date('N', strtotime('Monday')); 
like image 177
ceejayoz Avatar answered Sep 29 '22 05:09

ceejayoz