Sqlserver
 sql >> डेटाबेस >  >> RDS >> Sqlserver

मानक प्रारूप स्ट्रिंग्स (टी-एसक्यूएल) का उपयोग कर SQL सर्वर में 'डेटाटाइमऑफसेट' स्वरूपण के उदाहरण

मैंने सोचा कि यह देखने के लिए कुछ त्वरित प्रश्नों को चलाना दिलचस्प होगा कि विभिन्न स्वरूपण तार दिनांक/समय मानों के स्वरूपण को कैसे प्रभावित करते हैं।

उदाहरण 1 - अपरिवर्तनीय संस्कृति

DECLARE @date datetimeoffset, @culture char(2); 
SET @date = '2030-05-25 23:59:30.1234567 +07:00';
SET @culture = 'iv';
SELECT 
  FORMAT(@date, 'd', @culture) AS 'd',
  FORMAT(@date, 'D', @culture) AS 'D',
  FORMAT(@date, 'f', @culture) AS 'f',
  FORMAT(@date, 'F', @culture) AS 'F',
  FORMAT(@date, 'g', @culture) AS 'g',
  FORMAT(@date, 'G', @culture) AS 'G',
  FORMAT(@date, 'm', @culture) AS 'm',
  FORMAT(@date, 'M', @culture) AS 'M',
  FORMAT(@date, 'o', @culture) AS 'o',
  FORMAT(@date, 'O', @culture) AS 'O',
  FORMAT(@date, 'r', @culture) AS 'r',
  FORMAT(@date, 'R', @culture) AS 'R',
  FORMAT(@date, 's', @culture) AS 's',
  FORMAT(@date, 't', @culture) AS 't',
  FORMAT(@date, 'T', @culture) AS 'T',
  FORMAT(@date, 'u', @culture) AS 'u',
  FORMAT(@date, 'U', @culture) AS 'U',
  FORMAT(@date, 'y', @culture) AS 'y',
  FORMAT(@date, 'Y', @culture) AS 'Y';

परिणाम (ऊर्ध्वाधर आउटपुट का उपयोग करके):

d | 05/25/2030
D | Saturday, 25 May 2030
f | Saturday, 25 May 2030 23:59
F | Saturday, 25 May 2030 23:59:30
g | 05/25/2030 23:59
G | 05/25/2030 23:59:30
m | May 25
M | May 25
o | 2030-05-25T23:59:30.1234567+07:00
O | 2030-05-25T23:59:30.1234567+07:00
r | Sat, 25 May 2030 16:59:30 GMT
R | Sat, 25 May 2030 16:59:30 GMT
s | 2030-05-25T23:59:30
t | 23:59
T | 23:59:30
u | 2030-05-25 16:59:30Z
U | NULL
y | 2030 May
Y | 2030 May

उदाहरण 2 - यूएस अंग्रेज़ी

DECLARE @date datetimeoffset, @culture char(5);
SET @date = '2030-05-25 23:59:30.1234567 +07:00';
SET @culture = 'en-us';
SELECT 
  FORMAT(@date, 'd', @culture) AS 'd',
  FORMAT(@date, 'D', @culture) AS 'D',
  FORMAT(@date, 'f', @culture) AS 'f',
  FORMAT(@date, 'F', @culture) AS 'F',
  FORMAT(@date, 'g', @culture) AS 'g',
  FORMAT(@date, 'G', @culture) AS 'G',
  FORMAT(@date, 'm', @culture) AS 'm',
  FORMAT(@date, 'M', @culture) AS 'M',
  FORMAT(@date, 'o', @culture) AS 'o',
  FORMAT(@date, 'O', @culture) AS 'O',
  FORMAT(@date, 'r', @culture) AS 'r',
  FORMAT(@date, 'R', @culture) AS 'R',
  FORMAT(@date, 's', @culture) AS 's',
  FORMAT(@date, 't', @culture) AS 't',
  FORMAT(@date, 'T', @culture) AS 'T',
  FORMAT(@date, 'u', @culture) AS 'u',
  FORMAT(@date, 'U', @culture) AS 'U',
  FORMAT(@date, 'y', @culture) AS 'y',
  FORMAT(@date, 'Y', @culture) AS 'Y';

परिणाम (ऊर्ध्वाधर आउटपुट का उपयोग करके):

d | 5/25/2030
D | Saturday, May 25, 2030
f | Saturday, May 25, 2030 11:59 PM
F | Saturday, May 25, 2030 11:59:30 PM
g | 5/25/2030 11:59 PM
G | 5/25/2030 11:59:30 PM
m | May 25
M | May 25
o | 2030-05-25T23:59:30.1234567+07:00
O | 2030-05-25T23:59:30.1234567+07:00
r | Sat, 25 May 2030 16:59:30 GMT
R | Sat, 25 May 2030 16:59:30 GMT
s | 2030-05-25T23:59:30
t | 11:59 PM
T | 11:59:30 PM
u | 2030-05-25 16:59:30Z
U | NULL
y | May 2030
Y | May 2030

उदाहरण 3 - ब्रिटिश

DECLARE @date datetimeoffset, @culture char(5);
SET @date = '2030-05-25 23:59:30.1234567 +07:00';
SET @culture = 'en-gb';
SELECT 
  FORMAT(@date, 'd', @culture) AS 'd',
  FORMAT(@date, 'D', @culture) AS 'D',
  FORMAT(@date, 'f', @culture) AS 'f',
  FORMAT(@date, 'F', @culture) AS 'F',
  FORMAT(@date, 'g', @culture) AS 'g',
  FORMAT(@date, 'G', @culture) AS 'G',
  FORMAT(@date, 'm', @culture) AS 'm',
  FORMAT(@date, 'M', @culture) AS 'M',
  FORMAT(@date, 'o', @culture) AS 'o',
  FORMAT(@date, 'O', @culture) AS 'O',
  FORMAT(@date, 'r', @culture) AS 'r',
  FORMAT(@date, 'R', @culture) AS 'R',
  FORMAT(@date, 's', @culture) AS 's',
  FORMAT(@date, 't', @culture) AS 't',
  FORMAT(@date, 'T', @culture) AS 'T',
  FORMAT(@date, 'u', @culture) AS 'u',
  FORMAT(@date, 'U', @culture) AS 'U',
  FORMAT(@date, 'y', @culture) AS 'y',
  FORMAT(@date, 'Y', @culture) AS 'Y';

परिणाम (ऊर्ध्वाधर आउटपुट का उपयोग करके):

d | 25/05/2030
D | 25 May 2030
f | 25 May 2030 23:59
F | 25 May 2030 23:59:30
g | 25/05/2030 23:59
G | 25/05/2030 23:59:30
m | 25 May
M | 25 May
o | 2030-05-25T23:59:30.1234567+07:00
O | 2030-05-25T23:59:30.1234567+07:00
r | Sat, 25 May 2030 16:59:30 GMT
R | Sat, 25 May 2030 16:59:30 GMT
s | 2030-05-25T23:59:30
t | 23:59
T | 23:59:30
u | 2030-05-25 16:59:30Z
U | NULL
y | May 2030
Y | May 2030

उदाहरण 4 - जर्मन

DECLARE @date datetimeoffset, @culture char(2);
SET @date = '2030-05-25 23:59:30.1234567 +07:00';
SET @culture = 'de';
SELECT 
  FORMAT(@date, 'd', @culture) AS 'd',
  FORMAT(@date, 'D', @culture) AS 'D',
  FORMAT(@date, 'f', @culture) AS 'f',
  FORMAT(@date, 'F', @culture) AS 'F',
  FORMAT(@date, 'g', @culture) AS 'g',
  FORMAT(@date, 'G', @culture) AS 'G',
  FORMAT(@date, 'm', @culture) AS 'm',
  FORMAT(@date, 'M', @culture) AS 'M',
  FORMAT(@date, 'o', @culture) AS 'o',
  FORMAT(@date, 'O', @culture) AS 'O',
  FORMAT(@date, 'r', @culture) AS 'r',
  FORMAT(@date, 'R', @culture) AS 'R',
  FORMAT(@date, 's', @culture) AS 's',
  FORMAT(@date, 't', @culture) AS 't',
  FORMAT(@date, 'T', @culture) AS 'T',
  FORMAT(@date, 'u', @culture) AS 'u',
  FORMAT(@date, 'U', @culture) AS 'U',
  FORMAT(@date, 'y', @culture) AS 'y',
  FORMAT(@date, 'Y', @culture) AS 'Y';

परिणाम (ऊर्ध्वाधर आउटपुट का उपयोग करके):

d | 25.05.2030
D | Samstag, 25. Mai 2030
f | Samstag, 25. Mai 2030 23:59
F | Samstag, 25. Mai 2030 23:59:30
g | 25.05.2030 23:59
G | 25.05.2030 23:59:30
m | 25. Mai
M | 25. Mai
o | 2030-05-25T23:59:30.1234567+07:00
O | 2030-05-25T23:59:30.1234567+07:00
r | Sat, 25 May 2030 16:59:30 GMT
R | Sat, 25 May 2030 16:59:30 GMT
s | 2030-05-25T23:59:30
t | 23:59
T | 23:59:30
u | 2030-05-25 16:59:30Z
U | NULL
y | Mai 2030
Y | Mai 2030

निम्न तालिका प्रत्येक प्रारूप स्ट्रिंग के लिए विवरण प्रदान करती है।

DECLARE @thedatetimeoffset datetimeoffset = '2030-05-25 23:59:30.1234567 +12:15';

SELECT 
  FORMAT(@thedatetimeoffset, 'd') AS 'd (Short date)',
  FORMAT(@thedatetimeoffset, 'D') AS 'D (Long date)',
  FORMAT(@thedatetimeoffset, 'f') AS 'f (Full date/time - short time)',
  FORMAT(@thedatetimeoffset, 'F') AS 'F (Full date/time - long time)',
  FORMAT(@thedatetimeoffset, 'g') AS 'g (General date/time - short time)',
  FORMAT(@thedatetimeoffset, 'G') AS 'G (General date/time - long time)',
  FORMAT(@thedatetimeoffset, 'm') AS 'm (Month/day)',
  FORMAT(@thedatetimeoffset, 'M') AS 'M (Month/day)',
  FORMAT(@thedatetimeoffset, 'o') AS 'o (Round-trip date/time)',
  FORMAT(@thedatetimeoffset, 'O') AS 'O (Round-trip date/time)',
  FORMAT(@thedatetimeoffset, 'r') AS 'r (RFC1123)',
  FORMAT(@thedatetimeoffset, 'R') AS 'R (RFC1123)',
  FORMAT(@thedatetimeoffset, 's') AS 's (Sortable date/time)',
  FORMAT(@thedatetimeoffset, 't') AS 't (Short time)',
  FORMAT(@thedatetimeoffset, 'T') AS 'T (Long time)',
  FORMAT(@thedatetimeoffset, 'u') AS 'u (Universal sortable date/time)',
  FORMAT(@thedatetimeoffset, 'U') AS 'U (Universal full date/time)',
  FORMAT(@thedatetimeoffset, 'y') AS 'y (Year/month)',
  FORMAT(@thedatetimeoffset, 'Y') AS 'Y (Year/month)';

परिणाम:

d (Short date)                     | 5/25/2030
D (Long date)                      | Saturday, May 25, 2030
f (Full date/time - short time)    | Saturday, May 25, 2030 11:59 PM
F (Full date/time - long time)     | Saturday, May 25, 2030 11:59:30 PM
g (General date/time - short time) | 5/25/2030 11:59 PM
G (General date/time - long time)  | 5/25/2030 11:59:30 PM
m (Month/day)                      | May 25
M (Month/day)                      | May 25
o (Round-trip date/time)           | 2030-05-25T23:59:30.1234567+12:15
O (Round-trip date/time)           | 2030-05-25T23:59:30.1234567+12:15
r (RFC1123)                        | Sat, 25 May 2030 11:44:30 GMT
R (RFC1123)                        | Sat, 25 May 2030 11:44:30 GMT
s (Sortable date/time)             | 2030-05-25T23:59:30
t (Short time)                     | 11:59 PM
T (Long time)                      | 11:59:30 PM
u (Universal sortable date/time)   | 2030-05-25 11:44:30Z
U (Universal full date/time)       | NULL
y (Year/month)                     | May 2030
Y (Year/month)                     | May 2030

  1. Database
  2.   
  3. Mysql
  4.   
  5. Oracle
  6.   
  7. Sqlserver
  8.   
  9. PostgreSQL
  10.   
  11. Access
  12.   
  13. SQLite
  14.   
  15. MariaDB
  1. क्या हर कोई बादल की ओर पलायन कर रहा है?

  2. SQL सर्वर में केस संवेदनशील चर

  3. SQL सर्वर शो टेबल समतुल्य

  4. pyodbc डेटाबेस से कनेक्ट नहीं हो सकता

  5. अल्पविराम से अलग किए गए मान अलग करें और sql सर्वर में तालिका में संग्रहीत करें