Extract date from date and time - c++

I am using a VCL forms application in C++ Builder.
How can I get just the date from a TDateTime object that has both a date and a time associated with it?
Here is an example:
TDateTime test("25/09/2012 12:00am");
I am after a TDateTime object that has just the following information:
"25/09/2012"
Thanks

You can use DateOf
However, note that it will return "25/09/2012 00:00" as TDateTime type includes the time, so if you really need TDateTime returned you can't avoid the hour:minute info.
If you want to extract day/month/year info from TDateTime you can use DecodeDate function

Related

Graphlab Date Manipulaiton

I have a dataset that I am trying to manipulate in GraphLab. I want to convert a UNIX Epoch timestamp from the input file (converted to an SFrame) into a human readable format so I can do analysis based on hour of day and day of week.
time_array is the column/feature of the SFrame sf representing the timestamp, I have broken out just the EPOCH time to simplify things. I know how to convert the time of one row, but I want a vector operation. Here is what I have for one row.
time_array = sf['timestamp']
datetime.datetime.fromtimestamp(time_array[0]).strftime('%Y-%m-%d %H')
You can also get parts of the time from the timestamp to create another column, by which to filter (e.g., get the hour):
sf['hour'] = [x.strftime('%H')for x in sf['timestamp']]
So after staring at this for awhile and then posting the question it came to me, hopefully someone else can benefit as well. Use the .apply method with the datetime.datetime() function
sf['date_string'] = sf['timestamp'].apply(lambda x: datetime.datetime.fromtimestamp(x).strftime('%Y-%m-%d %H'))
you can also use the split_datetime API to split the timestamp to multiple columns:
split_datetime('timestamp',limit=['hour','minute'])

Is it possible to work with DateTime value in C++?

I'm working with an API which offers date and time data as a double precision decimal value, which is compatible with the Windows Date/Time format. I'm writing a program in C++ and I'd like to be able to access elements of the data contained within the double Date/Time value and format them as human readable. For example take the Date/Time value like so 41411.583333 and print a string as DD/MM/YYYY HH:MM:SS using C++. Please can someone explain if/how this can be done?
The COleDateTime class (provided in the MFC and ATL libraries) provides everything you need. It includes a Format member function that can print date/time in numerous formats:
http://msdn.microsoft.com/en-us/library/c1ayhyhk(v=vs.80).aspx
There's also the Boost.Date_Time library. Documentation here.

what is win32_NTLogEvent time generated format

what is the meaning of eventlog time generated value in wmi "20061101185842.000000-000".
when i am using windows event viewer it gives the date and time format as " 2/13/2013 4:05:15 PM " but when i am accessing it in win32_NTLogEvent, it gives the format as "20061101185842.000000-000".
please clear my doubt...
Thanks in advance...
The WMI uses the Universal Time Coordinate (UTC) format, try these articles for more information.
Working with Dates and Times using WMI
Converting WMI Dates to a Standard Date-Time Format
WMI Date and Time Format (Windows)
You can convert it to DateTime like this:
ManagementDateTimeConverter.ToDateTime(yourValue);
where yourValue is a string like this: "20061101185842.000000-000"

Combining two TDateTime variables

I am using C++ Builder in a VCL forms application.
I am wanting to create one TDateTime variable that is made up of two TDateTimePicker controls.
One of the controls is in the Date format and the other is in the Time format.
I am wanting to combine them both into one TDateTime variable.
For example, the DateTimePickerAppointmentDate shows "25/09/2012" and the DateTimePickerAppointmentTime shows "7:02:13 p.m."
I have tried the following code:
TDateTime testCombine = DateTimePickerAppointmentDate->Date + DateTimePickerAppointmentTime->Time;
However, the DateTimePickerAppointmentDate->Date is not just the date from the control, it is the Date and Time. Same goes for the DateTimePickerAppointmentTime->Time.
Do I have to separate the Date and Time from each to get the desired output via a function, or is there a feature of the DateTimePicker to just return the date or time from the controls?
Thanks
Solved it. Here is my code:
TDateTime appDate = DateOf(DateTimePickerAppointmentDate->Date) + TimeOf(DateTimePickerAppointmentTime->Time);

What is the correct way to handle timezones in datetimes input from a string in Qt

I'm using Qt to parse an XML file which contains timestamps in UTC. Within the program, of course, I'd like them to change to local time. In the XML file, the timestamps look like this: "2009-07-30T00:32:00Z".
Unfortunately, when using the QDateTime::fromString() method, these timestamps are interpreted as being in the local timezone. The hacky way to solve this is to add or subtract the correct timezone offset from this time to convert it to "true" local time. However, is there any way to make Qt realize that I am importing a UTC timestamp and then automatically convert it to local time?
Do it like this:
QDateTime timestamp = QDateTime::fromString(thestring);
timestamp.setTimeSpec(Qt::UTC); // mark the timestamp as UTC (but don't convert it)
timestamp = timestamp.toLocalTime() // convert to local time
try using the setTime_t function.
Note that full time zone support is not available yet in Qt, but probably will in future versions.
http://bugreports.qt-project.org/browse/QTBUG-10219