473,385 Members | 1,907 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Error in MySQL Online Reference?

Hello all,

I was browsing through the reference manual on the mysql.com web site and
found the following code examples for some date/time functions:

mysql> SELECT STR_TO_DATE('00/00/0000', '%m/%d/%Y');
-> '0000-00-00'

mysql> SELECT STR_TO_DATE('04/31/2004', '%m/%d/%Y');
-> '2004-04-31'

In each example above the first line is the code the second is the result.
Do these look backwards to anyone else? I'll admit I'm a newbie that's
browsing the boards and trying to decide if I want to learn MySQL and PHP,
but to me the following makes more sense:

mysql> SELECT STR_TO_DATE('2004-04-31', '%m/%d/%Y');
-> '04/31/2004'

The online manual's example would indicate that the "format" portion of the
function (%m/%d/%Y) should be specifying the format of the INPUT string.
I'm thinking that the "format" portion of the function should be specifying
the RESULT format as in my example (based upon my experience with Oracle and
Brio).

So, do I have a lot to learn or are the first two examples incorrect?

Thanks,

Phil
Jul 23 '05 #1
2 1517
Phil Nospam wrote:
,
but to me the following makes more sense:

mysql> SELECT STR_TO_DATE('2004-04-31', '%m/%d/%Y');
-> '04/31/2004' So, do I have a lot to learn or are the first two examples incorrect?


Examples are correct and you still got lot to learn.

If you want to convert str_to_date (String to date), you have a string
and the result will be a date. MySQL saves the dates in yyyy-mm-dd
format, so the format of result is always the same, unless you use a
specific function to convert the date into string, that looks like a
date in different format.

So the second value for str_to_date is the format of the first
parameter, because without it, MySQL couldn't know for example what does
user mean by "1/2/2005" (In Finland, that is 2005-02-01, but in USA that
is 2005-01-02), and that kind of a function wouldn't be very usefull.

If you want to convert MySQL date into string, you can use
DATE_FORMAT(date,format)

For example:
mysql> SELECT DATE_FORMAT('1997-10-04 22:23:00', '%W %M %Y');
-> 'Saturday October 1997'

You can of course get results like "10/04/1997" out from it. The example
just demonstrates that the result is not a date, it is a string.

Summary:
So two different functions. Other changes string to date, and other date
to string.
Jul 23 '05 #2
Phil Nospam wrote:
So, do I have a lot to learn or are the first two examples incorrect?


Well, one thing you could learn is to try the query yourself against the
test database. Empirical evidence is better than a thousand words:

mysql> SELECT STR_TO_DATE('2004-04-31', '%m/%d/%Y');
-> NULL
mysql> SELECT STR_TO_DATE('2004-04-31', '%Y/%m/%d');
-> NULL
mysql> SELECT STR_TO_DATE('2004-04-31', '%Y-%m-%d');
-> '2004-04-31'

Looks like the second argument is indeed the _input_ format specifier.

Regards,
Bill K.
Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Wayno | last post by:
My php logs are coming up empty. I have done all I can think of, and all that made sense to me. Can someone take a look at my php.ini please and tell me what you think may be the problem. I...
2
by: David | last post by:
I do some website design here and there occasionally for a few clients and I've got a new one that wants a database with their website that will display pricelists displayed for their products and...
2
by: MLH | last post by:
I am brand new both to linux and to mysql. When I type mysql on my linux box, the mysql monitor appears. There, I know how to type help and exit. that's all I know. I need a book or online...
175
by: Sai Hertz And Control Systems | last post by:
Dear all, Their was a huge rore about MySQL recently for something in java functions now theirs one more http://www.mysql.com/doc/en/News-5.0.x.html Does this concern anyone. What I...
4
by: RM | last post by:
Had VS .Net 2002 installed on W2k Server SP3 and supported a number of web sites. Installed VS .Net 2003 on Friday and now all web sites using .Net & MS ACCESS get this strange error upon open. ...
15
by: David Lozzi | last post by:
Howdy, I have a function that uploads an image and that works great. I love ..Nets built in upload, so much easier than 3rd party uploaders! Now I am making a public function that will take the...
15
by: Cheryl Langdon | last post by:
Hello everyone, This is my first attempt at getting help in this manner. Please forgive me if this is an inappropriate request. I suddenly find myself in urgent need of instruction on how to...
1
by: Thaqalainnaqvi | last post by:
IPB WARNING mysql_connect() : Too many connections (Line: 131 of /ips_kernel/class_db_mysql.php) There appears to be an error with the database. You can try to refresh the page by clicking...
4
by: yogesh | last post by:
mysql in c++ initialize error occurs a simple program is executed in redhat9.0 , using gcc 3.2.2 compiler version ... #include <stdio.h> #include <mysql.h> #include <string.h> int main() {
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.