MySQL Forums
Forum List  »  Connector/C++

Re: Selecting a date column
Posted by: Andrey Hristov
Date: September 28, 2009 01:04AM

Hi,
date comparison is pretty easy, if you fetch the data with getString().
Here is an exmaple of the format MySQL uses:
mysql> select now();
+---------------------+
| now() |
+---------------------+
| 2009-09-28 09:58:24 |
+---------------------+
1 row in set (0.00 sec)

You can directly string compare the strings, because it is guaranteed that the normal string comparison will be also the natural time order. Also, you can see that every position uses 2 bytes, except the year, so you can parse it pretty easy with offsets, if you wish that.
By using DATE_FORMAT you can your own format, for example similar output will be
20090928, and then you just need to use getInt().

mysql> select date_format(now(),"%Y%m%d");
+-----------------------------+
| date_format(now(),"%Y%m%d") |
+-----------------------------+
| 20090928 |
+-----------------------------+
1 row in set (0.00 sec)

Best,
Andrey

Options: ReplyQuote


Subject
Views
Written By
Posted
4395
September 24, 2009 08:31PM
2360
September 25, 2009 09:46AM
3530
September 25, 2009 10:43AM
Re: Selecting a date column
2730
September 28, 2009 01:04AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.