Reputation: 191
I get date (ex. 2015-06-12) and i want to get day of week...
For example Monday = 1
$dateprog=$_GET['dateprog'];
$dow = date("N",$dateprog);
but it's not working
Upvotes: 0
Views: 3058
Reputation: 1244
The variable $dateprog is in string format which you are extracting from the
$_GET['dateprog']
and parsing it as a parameter to the date function. However, the date function takes timestamp or date format as its second parameter
string date ( string $format [, int $timestamp = time() ] )
See documentation : Date
In order to convert the string to timestamp use the strtotime function as follows:
if(isset($_GET['dateprog']))
{
$dateprog = $_GET['dateprog'];
$dow = date("N",strtotime($dateprog));
echo $dow;
}
Upvotes: 3
Reputation: 692
just cast it to time:
$dateprog=$_GET['dateprog'];
$dow = date("N",strtotime($dateprog));
Upvotes: 0
Reputation: 31749
Try with -
if (!empty($_GET['dateprog'])) {
$dateprog=$_GET['dateprog'];
$dow = date("N",strtotime($dateprog));
echo $dow; // will print the day number of the week
}
Upvotes: 0