Skip to content

Instantly share code, notes, and snippets.

@nihilismus
Last active December 17, 2015 21:29
Show Gist options
  • Save nihilismus/5674639 to your computer and use it in GitHub Desktop.
Save nihilismus/5674639 to your computer and use it in GitHub Desktop.

De http://dev.mysql.com/doc/refman/5.0/es/date-and-time-functions.html

Para "sumar" un día a fecha_registro:

mysql> SELECT '2013-05-31' + INTERVAL 1 DAY;
+-------------------------------+
| '2013-05-31' + INTERVAL 1 DAY |
+-------------------------------+
| 2013-06-01                    |
+-------------------------------+
1 row in set (0.00 sec)

mysql> SELECT DATE_ADD('2013-05-31', INTERVAL 1 DAY);
+----------------------------------------+
| DATE_ADD('2013-05-31', INTERVAL 1 DAY) |
+----------------------------------------+
| 2013-06-01                             |
+----------------------------------------+
1 row in set (0.00 sec)

mysql>

Para determinar que nombre tiene la fecha obtenida en el anterior paso:

mysql> SELECT DAYNAME('2013-06-01');
+-----------------------+
| DAYNAME('2013-06-01') |
+-----------------------+
| Saturday              |
+-----------------------+
1 row in set (0.00 sec)

mysql> SELECT DAYNAME('2013-06-02');
+-----------------------+
| DAYNAME('2013-06-02') |
+-----------------------+
| Sunday                |
+-----------------------+
1 row in set (0.01 sec)

mysql>

Siendo Saturday sábado y Sunday domingo.

De igual forma pueden usar la función DAYOFWEEK, la cual regresa 1 para Domingo y 7 para sábado:

mysql> SELECT DAYOFWEEK('2013-06-01');
+-------------------------+
| DAYOFWEEK('2013-06-01') |
+-------------------------+
|                       7 |
+-------------------------+
1 row in set (0.00 sec)

mysql> SELECT DAYOFWEEK('2013-06-02');
+-------------------------+
| DAYOFWEEK('2013-06-02') |
+-------------------------+
|                       1 |
+-------------------------+
1 row in set (0.00 sec)

mysql>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment