using current year in string to date function

shantanuo

The year is expected to be picked as current year instead of the 00 year as shown below.

mysql> select str_to_date('Jul 15 12:12:51', '%b %e %T');
+--------------------------------------------+
| str_to_date('Jul 15 12:12:51', '%b %e %T') |
+--------------------------------------------+
| 0000-07-15 12:12:51                        |
+--------------------------------------------+

Expected result:

| 2013-07-15 12:12:51                        |
raina77ow

Well, that's intended. Quoting the doc:

Unspecified date or time parts have a value of 0, so incompletely specified values in str produce a result with some or all parts set to 0. [...] “Zero” dates or dates with part values of 0 are permitted unless the SQL mode is set to disallow such values.

It's easy to fix, btw:

select str_to_date(CONCAT(YEAR(NOW()), ' ', 'Jul 15 12:12:51'), '%Y %b %e %T');
-- July, 15 2013 12:12:51+0000 

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Getting the year of the current date

From Dev

Add a year to a date in string format using php

From Dev

Teradata Find last 1 year using current date issue

From Dev

How to validate date within current year using jQuery Validate plugin

From Dev

current year's date of birth using oracle sql

From Dev

Setting year in date picker according to current year

From Dev

PHP - Changing date's year to current year

From Dev

mysql convert date to same date of current year

From Java

PHP date add 5 year to current date

From Dev

mysql convert date to same date of current year

From Dev

removing current time while converting date using Date function in javascript

From Dev

Making full year schedule of event using php date function

From Dev

Hive Current date function

From Java

Get start date of current financial year

From Dev

Creating a year/week format for current date in R

From Dev

Get the last day of the current year as date

From Dev

How to get start date of current year in iOS

From Dev

SQL Date Range from current year

From Dev

Get start date of current financial year

From Dev

How to get a specific date in the current year

From Dev

How to get current date in year type

From Dev

how to get month name using current date as input in function

From Dev

convert year week string to date

From Dev

convert year week string to date

From Dev

How to get the Current Year to Current date in sql server 2008

From Dev

SQL Server 2008 Function for Current Academic Year

From Dev

SQL Server 2008 Function for Current Academic Year

From Dev

Get Current Year in a View Using the Phoenix Framework

From Dev

How to get current Year Using VBA

Related Related

HotTag

Archive