Enter your mobile number below and we'll send you a link to download the free Kindle App. Then you can start reading Kindle books on your smartphone, tablet, or computer - no Kindle device required.
Getting the download link through email is temporarily not available. Please check back later.

  • Apple
  • Android
  • Windows Phone
  • Android

To get the free app, enter your mobile phone number.

Kindle Price: £20.18

Save £4.81 (19%)

includes VAT*
* Unlike print books, digital books are subject to VAT.

These promotions will be applied to this item:

Some promotions may be combined; others are not eligible to be combined with other offers. For details, please see the Terms & Conditions associated with these promotions.

Deliver to your Kindle or other device

Deliver to your Kindle or other device

MySQL in a Nutshell (In a Nutshell (O'Reilly)) by [Dyer, Russell]
Kindle App Ad

MySQL in a Nutshell (In a Nutshell (O'Reilly)) Kindle Edition

4.3 out of 5 stars 4 customer reviews

See all formats and editions Hide other formats and editions
Amazon Price
New from Used from
Kindle Edition
"Please retry"
£20.18

Length: 566 pages

Kindle Books from 99p
Load up your Kindle library before your next holiday -- browse over 500 Kindle Books on sale from 99p until 31 August, 2016. Shop now

Product Description

About the Author

Russell Dyer has worked full-time for several years as a free-lance writer of computer articles, primarily on MySQL. He has been working with MySQL AB as the editor of their new Knowledge Base since December 2004. He is the author of "MySQL in a Nutshell" (O'Reilly), and has published over ninety articles for several magazines: Dev Zone (a MySQL publication), Linux Journal, ONlamp.com, The Perl Journal, Red Hat Magazine, SysAdmin Magazine, Tech Republic, Unix Review, and XML.com. A list of his published articles with links to them can be found on his web site at http://russell.dyerhouse.com.

Excerpt. © Reprinted by permission. All rights reserved.

Chapter 6 Date and Time Functions

The ability to record dates and times in a MySQL database is a very common requirement. This chapter presents the date and time functions for MySQL.

Date and time data comprises only numeric strings, so it can be stored in a regular character column. However, by using temporal datatype columns, you can use several built-in functions offered by MySQL. Currently, five temporal datatypes are available: date, time, datetime, timestamp, and year. The date column type is only for recording the date and uses the format yyyy-mm-dd. The time column type is for recording time in the format hhh:mm:ss. To record a combination of date and time, you can use the datetime column type: yyyy-mm-dd hh:mm:ss. The timestamp column is similar to datetime, but is a little limited in its range of allowable time: it starts at the Unix epoch time (i.e., 1970-01-01) and ends at the end of 2037. Finally, the year datatype is used only for recording the year in a column.

Incidentally, any function that calls for a date or a time datatype will also accept a combined datetime datatype. For more information on date and time datatypes, see Appendix A.

Validation of date strings is limited: MySQL makes sure that months range only from 0 to 12, and days range from 0 to 31. Therefore, a date such as February 30would be accepted. Version 5.0.2 of MySQL will offer more refined validation that would reject such a date.

At the end of this introduction is a listing of date and time functions, grouped by type of function. The bulk of this chapter consists of an alphabetical listing of date and time functions, with explanations of each. Many functions come with examples, along with a resulting display. For help in locating functions, see the index at the back of this book.

For the examples in this chapter, I used the scenario of a professional services firm (e.g., a law firm or an investment advisory firm) that tracks appointments and seminars in MySQL.

Date and Time Functions Grouped by Type

This section lists the functions according to their purpose: to retrieve a time, extract an element of one, or perform calculations on it.

Determining the Date and Time
CURDATE( ), CURRENT_DATE, CURTIME( ), CURRENT_TIME, CURRENT_TIMESTAMP, NOW( ),LOCALTIME( ), LOCALTIMESTAMP( ), SYSDATE( ), UNIX_TIMESTAMP( ), UTC_DATE( ), UTC_TIME( ), UTC_TIMESTAMP( )

Extracting and Formatting the Date and Time
DATE( ), DATE_FORMAT( ), DAY( ), DAYNAME( ), DAYOFMONTH( ), DAYOFWEEK( ), DAYOFYEAR( ), EXTRACT( ), GET_FORMAT( ), HOUR( ), LAST_DAY( ), MAKEDATE( ), MAKETIME( ), MINUTE( ), MONTH( ), MONTHNAME( ), QUARTER( ), SECOND( ), STR_TO_DATE( ), TIME_FORMAT( ), TIMESTAMP( ), WEEK( ), WEEKDAY( ), WEEKOFYEAR( ), YEAR( ), YEARWEEK( )

Calculating and Modifying the Date and Time
ADDDATE( ), ADDTIME( ), CONVERT_TZ( ), DATE_ADD( ), DATE_SUB( ), DATEDIFF( ), FROM_DAYS( ), FROM_UNIXTIME( ), PERIOD_ADD( ), PERIOD_DIFF( ), SEC_TO_TIME( ), SUBDATE( ), SUBTIME( ), TIME_TO_SEC( ), TO_DAYS( ), TIMEDIFF( ), TIMESTAMPADD( ), TIMESTAMPDIFF( )

Date and Time Functions in Alphabetical Order

The rest of the chapter lists each function in alphabetical order.

ADDDATE( )
ADDDATE(date,INTERVAL value type)

This function adds the given interval of time to the date or time provided. This is an alias for DATE_ADD( ); see its definition for details and interval types.

UPDATE seminars
SET seminar_date = ADDDATE(seminar_date, INTERVAL 7 DAY)
WHERE seminar_date = '2004-12-15'';

This example postpones the seminar that was scheduled for December 15, 2004 to December 22—seven days later. As of Version 4.1 of MySQL, for adding days the second argument of the function may simply be the number of days (i.e., just 7 instead of INTERVAL 7 DAY).


Product details

  • Format: Kindle Edition
  • File Size: 1174 KB
  • Print Length: 566 pages
  • Simultaneous Device Usage: Unlimited
  • Publisher: O'Reilly Media; 2 edition (15 April 2008)
  • Sold by: Amazon Media EU S.à r.l.
  • Language: English
  • ASIN: B0043D2EJ0
  • Text-to-Speech: Enabled
  • X-Ray:
  • Word Wise: Not Enabled
  • Enhanced Typesetting: Not Enabled
  • Average Customer Review: 4.3 out of 5 stars 4 customer reviews
  • Amazon Bestsellers Rank: #719,583 Paid in Kindle Store (See Top 100 Paid in Kindle Store)
  •  Would you like to give feedback on images or tell us about a lower price?

Customer Reviews

4.3 out of 5 stars
5 star
3
4 star
0
3 star
0
2 star
1
1 star
0
See all 4 customer reviews
Share your thoughts with other customers

Top Customer Reviews

Format: Paperback Verified Purchase
I might as well just have printed off the MySQL on-line documentation, this book really adds little. It's not an introduction for a novice and it doesn't provide real in-depth technical information for the advanced user, it's essentially a language reference. Handy to have lying around, but not what I was hoping for.
Comment Was this review helpful to you? Yes No Sending feedback...
Thank you for your feedback.
Sorry, we failed to record your vote. Please try again
Report abuse
Format: Paperback
im currently studing IT on a degree course and as i had the same book borrowed from the school library, i knew it was written on high standard. even though i borrowed the newer version, i decided to buy this one - price decided it for me, but i can't say there is big difference in these two versions (the newer comes with couple new features built into the newer MySQL, but you still get all you need for building solid and powerful code in MySQL). i would definitely suggest buying the book - as a reference book it is published by O'Reilly and let's all be honest - they are the best ones for books of this kind. thanks
Comment One person found this helpful. Was this review helpful to you? Yes No Sending feedback...
Thank you for your feedback.
Sorry, we failed to record your vote. Please try again
Report abuse
Format: Paperback Verified Purchase
This has had extensive use in the last few months, as I have been creating a web site from scratch. It is best used in conjunction with Google, as there are both formal documentation and a lot of examples available there.

There is an error on pages 32 and 33 - the TEXT_FIELDS function mentioned doesn't exist without additional plugins, that are not part of the standard mysql distribution.
Comment Was this review helpful to you? Yes No Sending feedback...
Thank you for your feedback.
Sorry, we failed to record your vote. Please try again
Report abuse
Format: Paperback
I ordered this book mostly to refer to example SQL code, ranging from basic to complex queries. This book demonstrates and explains each example clearly (with drawn tables). Would definitely recommend it to those who wish to learn SQL. I received this item quickly and was amazed at the condition of the book. The item description warned of minor bookshelf wear but you could almost class the book as brand new. Extremely happy with it and would definitely purchase from the seller again.
1 Comment One person found this helpful. Was this review helpful to you? Yes No Sending feedback...
Thank you for your feedback.
Sorry, we failed to record your vote. Please try again
Report abuse
click to open popover