-9

It is displaying Thursday but Wednesday output, please help me fix it.........

My code

<?php
    date_default_timezone_set('Asia/Kolkata');
    $date = '2017/06/07';
    $weekday = date('l', strtotime($date)); 
    echo $weekday; //
?>

Thanks in advance

Ole V.V.
  • 81,772
  • 15
  • 137
  • 161
vinod
  • 45
  • 13

2 Answers2

1

Try this:

date_default_timezone_set('Asia/Kolkata');
$date = '2017/06/07';
$date = str_replace('/','-', $date);
$weekday = date('l', strtotime($date)); 
echo $weekday;
// Output: Wednesday

Phpfiddle link

Check the document here

Note: Dates in the m/d/y or d-m-y formats are disambiguated by looking at the separator between the various components: if the separator is a slash (/), then the American m/d/y is assumed; whereas if the separator is a dash (-) or a dot (.), then the European d-m-y format is assumed. If, however, the year is given in a two digit format and the separator is a dash (-, the date string is parsed as y-m-d. To avoid potential ambiguity, it's best to use ISO 8601 (YYYY-MM-DD) dates or DateTime::createFromFormat() when possible.

Mayank Pandeyz
  • 25,704
  • 4
  • 40
  • 59
1

You need to use date format "Y-m-d" to get the result you want. $date = '2017/06/07' means June 07, 2017.

If you want to get the day of July 06, 2017 then change

$date = '2017/06/07';

To

$date = '2017/07/06';
Sehdev
  • 5,486
  • 3
  • 11
  • 34