Re: [Cppcms-users] How to store/manipulate dates?
Brought to you by:
artyom-beilis
From: Artyom B. <art...@ya...> - 2012-02-06 08:04:26
|
Let's make an order: std::time_t - number POSIX time general time representation, time zone independent booster::ptime - POSIX time - general time representation as a number similar to time_t but with higher precision. Time zone independent. booster::locale::date_time - localized time representation. Internally similar to time_t but allows operations according to current locale for example what is the first day of this week which maybe Sunday or Monday according to the locale (US/FR) Internally time zone independent but operations are time zone dependent. Requires special locale for operations (not necessary global) std::tm Standard C++ date-time representation. Does not hold and information about time zone. So which one do you need? if you want to use ptime with cppdb: p = booster::ptime::universal_time(get<std::tm>(column)) p = booster::ptime::local_time(get<std::tm>(column)) statement.bind(booster::ptime::universal_time(p)); statement.bind(booster::ptime::local_time(p)); If you want to use boost::locale::date_time with cppdb, you need to convert it into std::tm or from std::tm Usually it is not stright-forward as date_time may use for example Hebrew or Japanese calendar and the conversion to std::tm would not be correct as Gregorian month and Hebrew month are different. So you need to convert it first to either time_t or booster::ptime and then to std::tm and the other way around. Of course you can set std::tm's fields manually if you know that boost::locale::date_time uses Gregorian calendar. If you want to store only date you have two options: Use string and format it as "YYYY-MM-DD" or use std::tm with relevant fields set if the SQL engine knows to convert one type to another. Artyom Beilis -------------- CppCMS - C++ Web Framework: http://cppcms.com/ CppDB - C++ SQL Connectivity: http://cppcms.com/sql/cppdb/ >________________________________ > From: "ele...@ex..." <ele...@ex...> >To: cpp...@li... >Sent: Monday, February 6, 2012 9:36 AM >Subject: Re: [Cppcms-users] How to store/manipulate dates? > >Ah yes, thank you. > >This is what im doing now - > >c.topics[i].created_at = >booster::ptime::local_time(r.get<std::tm>("created_at")); > >Next question is - what data type to use for storing only date? > >Thanks again >Petr > >> Sorry for the "late" reply. >> What you are looking for is this >> >> http://cppcms.com/cppcms_ref_v0_99/classbooster_1_1ptime.html >> >> greetings >> > > >------------------------------------------------------------------------------ >Try before you buy = See our experts in action! >The most comprehensive online learning library for Microsoft developers >is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3, >Metro Style Apps, more. Free future releases when you subscribe now! >http://p.sf.net/sfu/learndevnow-dev2 >_______________________________________________ >Cppcms-users mailing list >Cpp...@li... >https://lists.sourceforge.net/lists/listinfo/cppcms-users > > > |