tom000.info - Logo
  • News
  • About Me
  • Your Account
  • Polski/Polish
  • Contact
Menu
  • News
  • Portfolio
  • Publications
  • jMPD
  • Gallery
  • Polski/Polish
  • Contact
New articles
  • Framebuffer in Linux
  • MySQL - Transactions
  • MySQL - Regular expressions
  • MySQL - Date processing functions
Online
Visitors: 1
MySQL - Date processing functions

Author: tom000
Date: 2007-03-06 17:11:44

With the aid of some built-in functions you can processing date in MySQL database in very handy way. Now, here I'm going to presents few functions which you can use to implement this goals.

Basic functions


Getting current date: CURDATE(), or CURRENT_DATE. Functions returns actually date on MySQL database server in RRRR-MM-DD format. In case of use command SELECT CURDATE(); we receive 2006-12-13.


Getting current time: CURTIME(), or CURRENT_TIME. Functions returns actually time on MySQL database server in HH:MI:SS format. In case of use command SELECT CURTIME(); we receive 00:16:24.


Getting current date and time NOW(), SYSDATE(), or CURRENT_TIMESTAMP. Functions returns actually date and time in RRRR-MM-DD HH:MI:SS format. In case of use command SELECT NOW(); we receive 2006-12-13 00:21:49.


Adding intervals to date: DATE_ADD(date, INTERVAL unit). This function is adding to entered date specific number of units. In case of use command SELECT DATE_ADD(NOW(), INTERVAL 1 DAY); we receive current date with one day older.


Subtraction intervals of date: DATE_SUB(date, INTERVAL unit). This function is subtracting from entered date specific number of units. In case of use command SELECT DATE_SUB(NOW(), INTERVAL 1 DAY); we receive current date with one day younger.


Date elements

  • DAYOFWEEK(date) - returns day of week as number
  • WEEKDAY(date) - returns day of week as number (0 – Monday)
  • DAYOFMONTH(date) - returns day of month as number
  • DAYOFYEAR(date) - returns day of year as number
  • MONTH(date) – returns number of month in year
  • DAYNAME(date) – returns full name of day of week
  • MONTHNAME(date) – returns full name of month
  • QUARTER(date) – returns number of quarter
  • WEEK(date) – returns number of week in year
  • YEAR(date) - returns year
  • HOUR(date) – returns hour
  • MINUTE(date) – returns number of minutes
  • SECOND(date) - returns number of seconds
  • TO_DAYS(date) – returns number of days which left from beginning of our era.
  • FROM_DAYS(days) – returns date, which show number of days from beginning of our era.


« [1] 2 3 »

Comments

Add comment

Login :
Website :
Comment :
Image text :
Popular tags

browsers desktop directfb errors fbi framebuffer gallery graphic java jmpd kate linux mplayer mysql php portfolio private projects regexp software tests uml version vesa video windows

Other

Valid XHTML 1.1

Some Rights Reserved logo

statystyki www stat.pl

Copyleft (C) tom000.info 2004-2008. Some rights reserved