SQL – Dates and Times.

Slides:



Advertisements
Similar presentations
Widhy Hayuhardhika NP, S.Kom. Overview of database structure Connecting to MySQL database Selecting the database to use Using the require_once statement.
Advertisements

Paramount Health Group Benefit Portal for XL India Employees
CenterView Tables. Session Outline Table Wizard Basic Table structure Modify the Look & Feel Advanced features JEval expressions Macro variables.
Developing Effective Reports
1 Databases. 2 Simple selects The full syntax of the SELECT statement is complex, but the main clauses can be summarized as: SELECT select_list [INTO.
DML- Insert. DML Insert Update Delete select The INSERT INTO Statement The INSERT INTO statement is used to insert new rows into a table. Syntax INSERT.
Phonegap Bridge – File System CIS 136 Building Mobile Apps 1.
Practice Insight Instructional Webinar Series Reporting
Developing Effective Reports
© 2008 The McGraw-Hill Companies, Inc. All rights reserved. ACCESS 2007 M I C R O S O F T ® THE PROFESSIONAL APPROACH S E R I E S Lesson 4 – Creating New.
Database Design lecture 3_1 1 Database Design Lecture 3_1 Data definition in SQL.
HAP 709 – Healthcare Databases SQL Data Manipulation Language (DML) Updated Fall, 2009.
Microsoft Access 2010 Building and Using Queries.
Lesson 2.  To help ensure accurate data, rules that check entries against specified values can be applied to a field. A validation rule is applied to.
MS-Excel XP Lesson 6. NOW Function 1.Returns the current date and time formatted as a date and time. 2.A1  =NOW() 3.A2  Select Insert menu Select Function.
1 Structured Query Language (SQL). 2 Contents SQL – I SQL – II SQL – III SQL – IV.
9 Copyright © Oracle Corporation, All rights reserved. Creating and Managing Tables.
SQL Basic. What is SQL? SQL (pronounced "ess-que-el") stands for Structured Query Language. SQL is used to communicate with a database.
EXPRESSION Transformation. Introduction ►Transformations help to transform the source data according to the requirements of target system and it ensures.
Using Dates in Excel Stored as a “serial number” which represents the number of days that have taken place since the beginning of the year 1900 – 1/1/1900=1.
DAY 21: MICROSOFT ACCESS – CHAPTER 5 MICROSOFT ACCESS – CHAPTER 6 MICROSOFT ACCESS – CHAPTER 7 Aliya Farheen October 29,2015.
©Silberschatz, Korth and Sudarshan1 Structured Query Language (SQL) Data Definition Language Domains Integrity Constraints.
Academic Year 2015 Autumn. MODULE CC2006NI: Data Modelling and Database Systems Academic Year 2015 Autumn.
College of Information Technology, Universiti Tenaga Nasional1 Lab 2: Single-row Functions CISB224 01A CCSB244 01A Semester I, 2008/2009.
1 Organizing Information in Tables A table is information arranged in horizontal rows and vertical columns When you first insert a table into a document,
Database Access with SQL
Chapter 6 Modifying Cell Styles
Databases.
SQL – Python and Databases
CSE 103 Day 20 Jo is out today; I’m Carl
In this session, you will learn to:
Tables and Triggers.
Aggregate Functions and Collations
Chapter 10 Selected Single-Row Functions Oracle 10g: SQL
Python – Dates and Times
CIS 136 Building Mobile Apps
Open Source Server Side Scripting Permissions & Users
Unit 16 – Database Systems
SQL – Data types.
Introduction to Oracle9i: SQL
SQL DATE/TIME FUNCTIONS
Three Minute Timer Two Minute Timer One Minute Timer
Working with table in MS WORD
Building and Using Queries
Java Date ISYS 350.
SQL – Parameterized Queries
Week 7 March 8 SQL: Chronological Sort, SUBSTRing, ROUND
CIS 136 Building Mobile Apps
Date Functions Farrokh Alemi, Ph.D.
Defining a Database Schema
Rob Gleasure robgleasure.com
Java Date ISYS 350.
Session - 6 Sequence - 1 SQL: The Structured Query Language:
SCHOOL, DEPARTMENT, PROGRAM, OR OTHER TEXT IF NEEDED
Chapter 2: Creating And Modifying Database Tables
Introduction to Programming with Python
Rob Gleasure robgleasure.com
Kirkwood Center for Continuing Education
Lecture 5 SQL FUNCTIONS.
Java Date ISYS 350.
Session - 6 Sequence - 1 SQL: The Structured Query Language:
Chapter 6 Modifying Cell Styles
HTML Forms What are clients? What are servers?
2 Hours Minutes Seconds Insert Text Here.
Trainer: Bach Ngoc Toan– TEDU Website:
Database Instructor: Bei Kang.
Java Date ISYS 350.
Temporal Data Part V.
Working with dates and times
2 Hours Minutes Seconds Insert Text Here.
Presentation transcript:

SQL – Dates and Times

How many columns should be returned for the following query? SELECT *, students.*, name FROM students; 3 4 7 Syntax error students name grade enthusiasm Josh 3.5 8.7

SELECT * and Qualified Names SELECT * is shorthand for all the columns (in order) in the table. * can be qualified (i.e. students.*) to make it unambiguous which table's columns are being included.

Problems with representations of time Dates and Times are messy to represent. Sometimes we only care about one or the other ("March 3rd" or 10:35PM) Sometimes we want different precision (12:35.9995AM) And don't even get started on time zones. https://www.youtube.com/watch?v=-5wpm-gesOY Many competing standards https://xkcd.com/927/

ISO 8601 date: YYYY-MM-DD time: HH:MM:SS.SSS datetime: YYYY-MM-DD HH:MM:SS.SSS Big benefit: lexicographic sort is chronological sort! You can store this format as text, and convert to a date object on export. https://xkcd.com/1179/

How to add timestamps to SQLite CREATE TABLE birthdays (name TEXT, birthday TEXT); INSERT INTO birthdays VALUES ('Josh', '1988-11-01'), ('Tom', '1986-12-31 12:31:56.7'), ('Dick', '12:31:56.7'); SELECT * FROM birthdays; But without a common format you can't compare them

SQLite date and time functions Input is of the form: 'YYYY-MM-DD' 'HH:MM:SS.SSS' (seconds are optional) 'YYYY-MM-DD HH:MM:SS.SSS' 'now' You can modify the timestamp by adding / removing time: '99 days' '-2 hours' Details here: https://www.sqlite.org/lang_datefunc.html

SQLite date and time functions The functions date, time, and datetime will take an input, apply any modifiers and return the resulting string. SELECT date('now'); -- 2016-02-08 SELECT time('12:53', '1 hours'); -- 13:53:00 SELECT datetime('2014-04-15', '-3 days'); -- 2014-04-12 00:00:00

What should this return? SELECT date('12:34'); 0000-01-01 1970-01-01 2000-01-01 Error (no date specified)