List:General Discussion« Previous MessageNext Message »
From:walter harms Date:August 15 2008 11:56am
Subject:Re: Need help to query with timestamp in C++
View as plain text  

Kandy Wong wrote:
> Hi Saul,
> 
> I need to use C++ and I'm not writing a web application.
> Thanks anyway.



you can do something like:

select min(abs(timediff("<targettime>",timestamp))) from <table> where
<condition> ;

if you use the libmysql you can get the result as strings back (the method i prefer) and
convert them
in what ever you need.

re,
 wh


>
>>>
>>> The followings are the timestamp in the MySQL database:
>>> | 2008-08-05 03:56:09 | 1217933769 |
>>> | 2008-08-05 03:56:19 | 1217933779 |
>>> | 2008-08-05 03:56:29 | 1217933789 |
>>> | 2008-08-05 03:59:39 | 1217933979 |
>>> | 2008-08-05 03:59:49 | 1217933989 |
>>> | 2008-08-05 03:59:59 | 1217933999 |
>>> | 2008-08-05 04:02:39 | 1217934159 |
>>> | 2008-08-05 04:02:49 | 1217934169 |
>>> | 2008-08-05 04:02:59 | 1217934179 |
>>>
>>> For example, '2008-08-05 04:01:39' is the time provided by the user
>>> which
>>> does not exist in the database.  So, how can I return the closest data?
>>> I
>>> know I can make use of 'LIKE' but this will return more than one data.
>>> What is the best method to get the closest one?
>>> And what is the good connector (C++ to MySQL) to use?
>>> Any suggestion?
>>> Thank you.
>>>
>>> Kandy
>>>
>>>
>>
>> --
>> MySQL General Mailing List
>> For list archives: http://lists.mysql.com/mysql
>> To unsubscribe:    http://lists.mysql.com/mysql?unsub=1
>>
>>
> 
> 
Thread
Need help to query with timestamp in C++Kandy Wong15 Aug
  • Re: Need help to query with timestamp in C++Saul Bejarano15 Aug
    • Re: Need help to query with timestamp in C++Kandy Wong15 Aug
      • Re: Need help to query with timestamp in C++walter harms15 Aug
      • RE: Need help to query with timestamp in C++Jerry Schwartz15 Aug
  • Re: Need help to query with timestamp in C++DuĊĦan Pavlica15 Aug
    • Re: Need help to query with timestamp in C++Kandy Wong15 Aug
  • Re: Need help to query with timestamp in C++Warren Young15 Aug