I have price data for the Indian stock market, but the time and date stamp on it is GMT, so I can work with the data representing the correct date and time.
I need to convert the date and time for some of the records in my DB into IST from GMT, my current time zone.
mysql> desc price_hist;
+---------------+-----------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------------+-----------------------+------+-----+---------+----------------+
| trade_id | int(11) | NO | PRI | NULL | auto_increment |
| contract_name | varchar(14) | NO | MUL | NULL | |
| trade_date | date | NO | | NULL | |
| trade_time | varchar(6) | NO | | NULL | |
| trade_price | decimal(10,4) | NO | | NULL | |
| trade_volume | bigint(20) | NO | | NULL | |
+---------------+-----------------------+------+-----+---------+----------------+
8 rows in set (0.02 sec)
I tried to change the timezone in the DB itself by running, but that did not work:
select convert_tz("2010-06-30 19:00:00",'GMT','IST');
+-----------------------------------------------+
| convert_tz("2011-06-30 09:00:00",'GMT','IST') |
+-----------------------------------------------+
| NULL |
+-----------------------------------------------+
1 row in set (0.01 sec)
I am new to Boost, but I have been suggested to use Boost date to handle this in the code itself.
I searched some of the posts for datetime conversion but did not find a post that would answer my specific question.
If there is a specific link or better still, example boost code someone could share, that would be a great start for a nubee like me. :-)
I used the reference @Karison provided to write the following code:
#include "boost/date_time/local_time/local_time.hpp"
#include <iostream>
int main()
{
using namespace boost::posix_time;
using namespace boost::gregorian;
using namespace boost::local_time;
tz_database tz_db;
time_zone_ptr chi_tz=tz_db.time_zone_from_region("America/Chicago");
time_zone_ptr jst_tz(new posix_time_zone("EST+5:00:00"));
local_date_time jpn_time(date(2012,Jan,3), hours(16), jst_tz,local_date_time::NOT_DATE_TIME_ON_ERROR);
local_date_time osaka_time = jpn_time.local_time_in(chi_tz);
std::cout<<"osaka_time: "<<osaka_time<<std::endl;
return 0;
}