Difference between revisions of "Format a date and time"

From SQLZOO
Jump to: navigation, search
(Created page with "Format a date and time. <div class='ht'> <div class=params>schema:scott</div> <div> Many engines support the SQL standard - see Mimer for details. </div> <source lang=sql cla...")
 
Line 1: Line 1:
 
Format a date and time.
 
Format a date and time.
 
<div class='ht'>
 
<div class='ht'>
<div class=params>schema:scott</div>
+
<div class=params>schema:gisq</div>
 
<div>
 
<div>
 
Many engines support the SQL standard - see Mimer for details.
 
Many engines support the SQL standard - see Mimer for details.

Revision as of 11:54, 17 July 2012

Format a date and time.

schema:gisq

Many engines support the SQL standard - see Mimer for details.

DROP TABLE t_peep;
CREATE TABLE t_peep
 (id INTEGER PRIMARY KEY
 ,name VARCHAR(50))
SELECT CAST(EXTRACT(DAY FROM wk) AS VARCHAR(2))
       || '/' ||
       CAST(EXTRACT(MONTH FROM wk) AS VARCHAR(2))
       || '/' ||
       CAST(EXTRACT(YEAR FROM wk) AS VARCHAR(4)),
       song
 FROM totp
 WHERE singer='Tom Jones'
SELECT STRFTIME('%d/%m/%Y', wk), song
 FROM totp
 WHERE singer='Tom Jones'
SELECT DATE_FORMAT(wk,'%d/%m/%Y'), song
FROM totp
WHERE singer='Tom Jones'
SELECT CONVERT(VARCHAR(10), wk, 103), song
  FROM totp
 WHERE singer='Tom Jones'
SELECT TO_CHAR(wk, 'DD/MM/YYYY'), song
FROM totp
WHERE singer='Tom Jones'
SELECT FORMAT(wk, 'DD/MM/YYYY'),
       song
 FROM totp
 WHERE singer='Tom Jones'
SELECT CHAR(wk, eur),
       song
 FROM totp
 WHERE singer='Tom Jones'
Personal tools
Namespaces

Variants
Actions
Reference
Toolbox
Google AdSense