Date Handling - Parse Dates with MySQL (Page 4 of 4 )
MySQL has a similar function, calledSTR_TO_DATE. This works with the format strings in MySQL format:
INSERT INTO d VALUES (STR_TO_DATE('1 Jun 2006', '%d %b %Y'));
%brepresents the abbreviated month name,%dis the day of the month, and%Yis a four-digit year.
Parse Dates with SQL Server
If your input format is a fixed size (with leading zeros), combine theSUBSTRINGfunction to build the string. Convert a string such as'06/18/2006'into a date:
INSERT INTO d SELECT SUBSTRING(x,7,4)+'-'+ SUBSTRING(x,1,2)+'-'+ SUBSTRING(x,4,2) FROM (SELECT '06/18/2006' AS x) y;
Please check back next week for the continuation of this article.
DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.