Combining two TDateTime variables - c++

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);

Related

ColeDateTime::Format languagespecific different fields

I want to format a COleDateTime as a CString, so i use
COleDateTime dt = GetMyDateTimeObj();
dt.Format(LOCALE_NOUSEROVERRIDE, GetCurrentLocaleID());
Since my program is multilanguage, GetCurrentLocaleID gives me the LCID currently selected (not in windows but in my program).
So the above gives me the correctly formated string according to the selected user-language but its always in a format "date-with-year + time-with-seconds". I think this is the short format of a date and the long format of the time accordong to windows regional settings.
What can i do to get the String with
- the year as just 2 numbers?
- completely without the year?
- the time-part without seconds?
Are there any switches to COleDateTime::Format that can give me year-as-2-digits, time-without-seconds but keeps fieldorder and separators specified by the LCID?
Of course i dont want to change any windows-regional-settings to do this and i dont want to use any fixed format-strings like _T("%d.%m.%Y %H:%M:%S") as this would break language-specific order of fields and separators.
Thanks for your hints and answers
Micha

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'])

Modify date time to a specific format

I'm having trouble coding a conversion to a specific time format along with converting to string format. I have the following code.
txtMonday->Text = Convert::ToString(dtpMondayIn->Value);
I want txtMonday(text box) not only to display dtpMondayIn's value(datetimepicker), but in h.mm format. Currently, it will display the date and time, for example, January 1, 2014 8:40:30 AM. I want the text box to show only 8.40 as in hours and minutes. How could I code this? I'm using Visual Studio 2012 and c++ language.
I am not really sure but
try this,
txtMonday->Text = Convert::ToString(dtpMondayIn->Value.ToString("hh:mm tt",CultureInfo.InvariantCulture));
OR
Convert::ToString(dtpMondayIn->Value.ToString("hh:mm",CultureInfo.InvariantCulture));
Also check DATETIME PICKER VALUE PROP
and DATETIME FORMATS
Let me know in case it works.

Extract date from date and time

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

Parsing a date in ColdFusion

I have a date stored in the format dd-mm-yyyy. I want to store the day, date and year as individual variables, while getting rid of any leading zeros (e.g. "09-09-2010" is stored as 9, 9, 2010).
I attempted to use the code on this page to split the date by dashes, but it is throwing expression errors.
Some people, when confronted with a
problem, think "I know, I'll use
regular expressions." Now they have
two problems.
Coding Horror: Regular Expressions: Now You Have Two Problems
Investigate the ColdFusion functions month(date), day(date) and year(date).
Update: you can pass a string to these functions so long as CF can turn into a date.
When you say that you have a date
stored in the format dd-mm-yyyy
are you sure you aren't confusing this with the way that your database UI is presenting it to you or are you actually storing the date in this format (for example, by writing it this way to a text file or a varchar column rather than a DateTime column)?
The reason I ask is that if a date is stored in a database as a date then CF will represent it as a date irrespective of how it appears in, say, SQL Management Studio. If this is the case then you can simply split the parts out using DatePart("datepart", "date").
If you have a date in a text format (such as from a form submission or because it has been stored as plain text) then you should be able to parse it in to a DateTime object using LSParseDateTime() and then use the DatePart(...) method on it to split out the parts.
See http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=functions_c-d_30.html
(sorry, can't post the URL to the other function due to lack of SO points!)
for the documentation on this.
As an aside, if you are using SQL2005 (or later) then you can create computed columns on the date field in order to split out the day, year and month at the database level. I thought I'd mention this just in case it proves useful.
Steve
If you're working with a string in that format, there's no need for regular expressions.
myDate = "13-12-2010";
theDay = listGetAt(myDate,1,"-");
theMonth = listGetAt(myDate,2,"-");
theYear = listGetAt(myDate,3,"-");
Using the val() function will also drop leading zeroes, if any.