473,626 Members | 3,041 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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('20 04-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 1528
Phil Nospam wrote:
,
but to me the following makes more sense:

mysql> SELECT STR_TO_DATE('20 04-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(dat e,format)

For example:
mysql> SELECT DATE_FORMAT('19 97-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('20 04-04-31', '%m/%d/%Y');
-> NULL
mysql> SELECT STR_TO_DATE('20 04-04-31', '%Y/%m/%d');
-> NULL
mysql> SELECT STR_TO_DATE('20 04-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
5024
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 double-checked the path to my error log. It is in /var/www/logs/php_error_log Thanks. :) -Wayne Stevenson
2
1635
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 they want the ability to have individual logins for their customers. I'm more of a designer than a programmer and I've never really done anything complex with a database before, and certainly nothing with MySQL. I had someone who I thought was...
2
1482
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 source that will teach me to use the mysql monitor. Recommendations?
175
11348
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 think is PostgreSQL would have less USP's (Uniqe Selling Points
4
2529
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. ASP=/TestDotNet/AdoNet.aspx System.Data.OleDb.OleDbException: Unspecified error at System.Data.OleDb.OleDbConnection.ProcessResults(Int32 hr) at System.Data.OleDb.OleDbConnection.InitializeProvider() at System.Data.OleDb.OleDbConnection.Open()...
15
5329
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 path of the uploaded image, and resize it with the provided dimensions. My function is below. The current function is returning an error when run from the upload function: A generic error occurred in GDI+. Not sure what exactly that means. From what...
15
4591
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 communicate with a MySQL database table on a web server, from inside of my company's Access-VBA application. I know VBA pretty well but have never before needed to do this HTTP/XML/MySQL type functions.
1
2987
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 here. Error Returned
4
3038
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
8192
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8696
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8637
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8358
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8502
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7188
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4090
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4195
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1805
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.