jingleboy99
jingleboy99

Reputation: 735

[mysql&php], what is the first day of a week, Monday or Sunday?

What is the first day of the week in mysql, Monday or Sunday??

I want to do this: (i am using php btw)

I am kinda of stuck while playing with the "date" thing. Can anyone help?

Upvotes: 0

Views: 994

Answers (1)

Josh
Josh

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

Related Questions