Date Functions in SQL Server and MySQL
Date Functions in SQL Server and MySQL
http://www.w3schools.com/sql/sql_dates.asp
ADVERTISEMENTS XML Certification Download XML editor Custom Programming WEB HOSTING SQL Basic SQL HOME SQL Intro SQL Syntax SQL Select SQL Distinct SQL Where SQL And & Or SQL Order By SQL Insert SQL Update SQL Delete SQL Demo SQL Try It SQL Advanced SQL Top SQL Like SQL Wildcards SQL In SQL Between SQL Alias SQL Joins SQL Inner Join SQL Left Join SQL Right Join SQL Full Join SQL Union SQL Select Into SQL Create DB SQL Create Table SQL Constraints SQL Not Null SQL Unique SQL Primary Key SQL Foreign Key SQL Check SQL Default SQL Create Index SQL Drop SQL Alter SQL Increment SQL Views SQL Dates SQL Nulls SQL isnull() SQL Data Types SQL Functions SQL Functions SQL avg() SQL count() SQL first() SQL last() SQL max() SQL min() SQL sum() SQL Group By SQL Having SQL ucase() SQL lcase() SQL mid() SQL len() SQL round() SQL now() SQL format() SQL Quick Ref SQL Hosting SQL Summary SQL Quiz SQL Quiz
SQL Dates
The most difficult part when working with dates is to be sure that the format of the date you are trying to insert, matches the format of the date column in the database. As long as your data contains only the date portion, your queries will work as expected. However, if a time portion is involved, it gets complicated. Before talking about the complications of querying for dates, we will look at the most important built-in functions for working with dates.
1 of 3
1/29/2009 11:53 AM
http://www.w3schools.com/sql/sql_dates.asp
Selected Reading Web Statistics Web Glossary Web Hosting Web Quality W3Schools Tutorials W3Schools Forum Helping W3Schools
Assume we have the following "Orders" table: OrderId 1 2 3 4 ProductName Geitost Camembert Pierrot Mozzarella di Giovanni Mascarpone Fabioli OrderDate 2008-11-11 2008-11-09 2008-11-11 2008-10-29
Now we want to select the records with an OrderDate of "2008-11-11" from the table above. We use the following SELECT statement:
Now, assume that the "Orders" table looks like this (notice the time component in the "OrderDate" column): OrderId 1 2 3 4 ProductName Geitost Camembert Pierrot Mozzarella di Giovanni Mascarpone Fabioli OrderDate 2008-11-11 13:23:44 2008-11-09 15:45:21 2008-11-11 11:12:01 2008-10-29 14:56:59
Product Spotlight
Why are you still hand-coding? Generate data entry and reporting .NET Web apps in minutes, straight from your database. Visually stunning, easy to customize and ready to deploy. Download Now!
Ektron CMS400.NET Version 7.6 delivers all of the flexibility and features you need to deploy the Web site you want, quickly and efficiently. learn more...
Create site stickiness through social networking. Keep it personal, relevant and interactive and they'll come back for more. Keep it open. Your site needs to be ready and able to connect to outside services. Ektron's open API gives you maximum flexibility. Streamline content and document management. Users need to quickly and intuitively find and add information. Empower your content authors. Reduce IT bottlenecks by allowing business users to create and edit Web content and forms. Climb to the top of search rankings. SEO tools, URL aliasing and eCommerce for your digital marketing strategy
2 of 3
1/29/2009 11:53 AM
http://www.w3schools.com/sql/sql_dates.asp
Add powerful W eb 2.0 tools like blogs, wikis, forums, geo-mapping, rating systems and RSS feeds easily.
See why there are 20,000+ Ektron integrations worldwide. Request an INSTANT DEMO or download a FREE TRIAL today.
Jump to: Top of Page or HOME or Printer Friendly Printer friendly page W3Schools is for training only. We do not warrant the correctness of its content. The risk from using it lies entirely with the user. While using this site, you agree to have read and accepted our terms of use and privacy policy. Copyright 1999-2009 by Refsnes Data. All Rights Reserved. W3Schools was converted to XHTML in 1999
3 of 3
1/29/2009 11:53 AM