dora
dora

Reputation: 1344

Finding the number of the day in a week in PHP from a date ( d-m-Y ) format

I have a variable $date='15-06-2013' . Now, how do I get the number of the day in the week? 15-06-2013 is a Saturday and hence my function should return 6 as the number if I were to use N format character

Upvotes: 1

Views: 104

Answers (2)

vascowhite
vascowhite

Reputation: 18440

Alternatively, using the DateTime class:-

echo (new \DateTime('15-06-2013'))->format('N');

Output:-

6

See it working

Upvotes: 0

Yogesh Suthar
Yogesh Suthar

Reputation: 30488

Use this code

echo $day_of_week = date('N', strtotime('15-06-2013'));

Output

6

Codepad

Upvotes: 2

Related Questions