Reputation: 735
What is the first day of the week in mysql, Monday or Sunday??
I want to do this: (i am using php btw)
Get today date (no problem)
Display information of this week (stuck here)
Previous and next week button, to display previous and next week data (cant do anything here)
I am kinda of stuck while playing with the "date" thing. Can anyone help?
Upvotes: 0
Views: 994
Reputation: 6322
Monday.
http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_weekday
WEEKDAY(date)
Returns the weekday index for date (0 = Monday, 1 = Tuesday, … 6 = Sunday).
To get details about previous or next weeks you can use
DATE_ADD(date,INTERVAL expr unit), DATE_SUB(date,INTERVAL expr unit)
eg SELECT DATE_ADD('2010-12-31 23:59:59', INTERVAL 1 WEEK);
http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_date-add
To get the weekday in PHP you can use the following:
<?php
$datetime = new DateTime('2010-12-31 23:59:59');
$today = $datetime->format('l');
echo $today;
?>
http://www.php.net/manual/en/function.date.php
Upvotes: 2