Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Database \ Convert MySQL date string to a NULL value exception handling     - The text formatting tools awk Linux system (Linux)

- How to manage Vim plugin (Linux)

- Six Ways to view slides can be implemented Android (Programming)

- LaTeX Getting Started Tutorial (Linux)

- Linux Network Programming --epoll model Detailed principles and examples (Programming)

- impdp error ORA-39001, ORA-39000, ORA-31619 (Database)

- Setting up Linux machine through a proxy firewall (Linux)

- Compile Android libwebcore.so error occurs when solving (Programming)

- Linux mention the right notes (Linux)

- HomeKit User Interface Guidelines (Linux)

- ssh port forwarding Comments (Server)

- Oracle 11g RAC manually playing GI PSU patch (11.2.0.4.8) (Database)

- MySQL stored procedures and triggers (Database)

- Setting grep Highlight Matches (Linux)

- Object Oriented Programming Java reflection (Programming)

- Linux System Getting Started Learning: the curl set custom HTTP header (Linux)

- Git commands (Linux)

- Binding multiple network cards in Linux using command nmcli (Linux)

- JDK comes with tools JPS (Linux)

- The oh-my-zsh into true my zsh (Linux)

 
         
  Convert MySQL date string to a NULL value exception handling
     
  Add Date : 2018-11-21      
         
         
         
  1, YYYYmmdd date format is converted to null

See the following records can take to a value less than the value of taking a **
mysql> SELECT DATE_FORMAT (STR_TO_DATE ( '20150922 13:01:01', '% Y% m% d% H:% m:% s'), '% H:% m');
+ ------------------------- +
| DATE_FORMAT (STR_TO_DATE ( '20150922 13:01:01', '% Y% m% d% H:% m:% s'), '% H:% m') |
+ ------------------------- +
| 13:01 |
+ ------------------------- +
1 row in set (0.00 sec)

mysql> SELECT DATE_FORMAT (STR_TO_DATE ( '20150922 12:55:00', '% Y% m% d% H:% m:% s'), '% H:% m');
+ ------------------------- +
| DATE_FORMAT (STR_TO_DATE ( '20150922 12:55:00', '% Y% m% d% H:% m:% s'), '% H:% m') |
+ ------------------------- +
| NULL |
+ ------------------------- +
1 row in set, 1 warning (0.00 sec)

mysql>

2, see the error message:

mysql> show warnings;
+ --- + - + ------------------------ +
| Level | Code | Message |
+ --- + - + ------------------------ +
| Warning | 1411 | Incorrect datetime value: '20150922 12:55:00' for function str_to_date |
+ --- + - + ------------------------ +
1 row in set (0.00 sec)

mysql>
Police say is Incorrect datetime value: '20150922 12:55:00' for function str_to_date, incorrect date format, it is replaced with a fairly standard date format

3, replaced with the canonical% Y-% m-% d% H:% i:% s try

mysql> select DATE_FORMAT (str_to_date ( '2015-09-22 13:00:01', '% Y-% m-% d% H:% i:% s'), '% H:% i');
+ -------------------------- +
| DATE_FORMAT (str_to_date ( '2015-09-22 13:00:01', '% Y-% m-% d% H:% i:% s'), '% H:% i') |
+ -------------------------- +
| 13:00 |
+ -------------------------- +
1 row in set (0.00 sec)

mysql> select DATE_FORMAT (str_to_date ( '2015-09-22 12:55:00', '% Y-% m-% d% H:% i:% s'), '% H:% i');
+ -------------------------- +
| DATE_FORMAT (str_to_date ( '2015-09-22 12:55:00', '% Y-% m-% d% H:% i:% s'), '% H:% i') |
+ -------------------------- +
| 12:55 |
+ -------------------------- +
1 row in set (0.00 sec)

mysql>

See in the canonical format, date conversion from string to date format, then the interception division are able to get the value.

Refer to the official website address: http: //dev.mysql.com/doc/refman/5.6/en/date-and-time-functions.html#function_str-to-date

4, it is determined to narrow again,% h is the problem, when you get into uppercase

To see a case, the format will become 2015-09-22 13:00:01 table ready format, you can still take less time value, as follows:

mysql> select DATE_FORMAT (str_to_date ( '2015-09-22 13:00:01', '% Y-% m-% d% h:% i:% s'), '% h:% i');
+ ------------------------------------------------- ----------------------------- +
| DATE_FORMAT (str_to_date ( '2015-09-22 13:00:01', '% Y-% m-% d% h:% i:% s'), '% h:% i') |
+ ------------------------------------------------- ----------------------------- +
| NULL |
+ ------------------------------------------------- ----------------------------- +
1 row in set, 1 warning (0.00 sec)

mysql> select DATE_FORMAT (str_to_date ( '2015-09-22 12:55:00', '% Y-% m-% d% h:% i:% s'), '% h:% i');
+ ------------------------------------------------- ----------------------------- +
| DATE_FORMAT (str_to_date ( '2015-09-22 12:55:00', '% Y-% m-% d% h:% i:% s'), '% h:% i') |
+ ------------------------------------------------- ----------------------------- +
| 12:55 |
+ ------------------------------------------------- ----------------------------- +
1 row in set (0.00 sec)

mysql>
Then the problem is where? Only Quguan network again searching for answers to find http://dev.mysql.com/doc/refman/5.6/en/date-and-time-functions.html#function_get-format
See the ultimate standard format: '.% Y-% m-% d% H.% i% s', into the try, to see examples of where the difference yet? The difference is that% H and% h ah, as follows:

mysql> select DATE_FORMAT (str_to_date ( '20150922 13:00:01', '% Y% m% d% h:% i:% s'), '% h:% i');
+ ------------------------------------------------- ------------------------- +
| DATE_FORMAT (str_to_date ( '20150922 13:00:01', '% Y% m% d% h:% i:% s'), '% h:% i') |
+ ------------------------------------------------- ------------------------- +
| NULL |
+ ------------------------------------------------- ------------------------- +
1 row in set, 1 warning (0.00 sec)

mysql> select DATE_FORMAT (str_to_date ( '20150922 12:55:00', '% Y% m% d% h:% i:% s'), '% h:% i');
+ ------------------------------------------------- ------------------------- +
| DATE_FORMAT (str_to_date ( '20150922 12:55:00', '% Y% m% d% h:% i:% s'), '% h:% i') |
+ ------------------------------------------------- ------------------------- +
| 12:55 |
+ ------------------------------------------------- ------------------------- +
1 row in set (0.00 sec)

mysql>
Then the standard date format:% Y% m% d% H:% i:% s 'or% Y-% m-% d% H:% i:% s' are as follows:

select DATE_FORMAT (str_to_date ( '20150922 13:00:01', '% Y% m% d% H:% i:% s'), '% H:% i');
select DATE_FORMAT (str_to_date ( '20150922 12:55:00', '% Y% m% d% H:% i:% s'), '% H:% i');
     
         
         
         
  More:      
 
- Ubuntu way of decompressing files (Linux)
- Use HttpClient remote interface testing (Programming)
- Ruby and Python simple comparison (Programming)
- Ubuntu 14.04 Enable root and disable the guest (Linux)
- Linux using DenyHosts prevents ssh cracks (Linux)
- CentOS achieve trash mechanism (Linux)
- Java synchronization mechanism used in locking Thought (Programming)
- Distributed Hadoop1.2.1 cluster installation (Server)
- Linux firewall security (Linux)
- Build RPM package uses Docker mirror (Linux)
- Ubuntu Server 14.04 installation Web server (Linux + Apache + MySQL + PHP) (Server)
- Linux System Getting Started Tutorial: Five image processing software (Linux)
- Java code JIT compiler-friendly Mody (Programming)
- SELinux security permissions HTTP + PHP service changes (Server)
- JavaScript prototype and prototype chain and project combat (Programming)
- Oracle Database import and export combat (Database)
- Linux installation JDK1.6 rpm.bin assembly (Linux)
- Traffic monitor Linux Python Version (Programming)
- Seven kinds of NIC binding mode Detail (Linux)
- Docker deployment practices in Ubuntu (Server)
     
           
     
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.