Modify date time to a specific format - c++

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.

Related

How can I get the current day in Robot Framework?

Im new to automated Testing.
Now I want to select the current weekday from a list.
I want to us following Keyword:
Selenium2Library.Select From List by Value ${day_of_the_week}
How can I get the Current day in Robot Framework? Is there a simple solution to my Problem?
The best would be a variable that gives me the current day in german Language.
I hope you can help me.
Using the Library DateTime
Which can be called by:
**** Settings ***
Library DateTime
You can use the Get Current Date keyword and assign it to a Var and specify the format. For example:
${CurrentDate} Get Current Date result_format=%d-%m-%Y
Log ${CurrentDate}
In your case you need to change the Result_format to retrieve the current day. This would be
${CurrentDay} Get Current Date result_format=%A
Log ${CurrentDay}
Which, when viewed in the log, would retrieve "Thursday"
The list of formats can be found here
Hope this helps you!
EDIT:
Due to the DateTime Library not supporting local names for the dates (Montag for Monday in German for instance) The Asker switched to the %w format to return 0-6 range. Then used an index to change the int into a string of the date!

Excel international date formatting

I am having problems formatting Excel datetimes, so that it works internationally. Our program is written in C++ and uses COM to export data from our database to Excel, and this includes datetime fields.
If we don't supply a formatting mask, some installations of Excel displays these dates as Serial numbers (days since 1900.01.01 followed by time as a 24-hour fraction). This is unreadable to a human, so we ha found out that we MUST supply a date formatting mask to be sure that it displays readable.
The problem - as I see it - is that Excel uses international formatting masks. For example; the UK datetime format mask might be "YYYY-MM-DD HH:MM".
But if the format mask is sent to an Excel that is installed in Sweden, it fails since the Swedish version of the Excel uses "ÅÅÅÅ-MM-DD tt:mm".
It's highly impractical to have 150 different national datetime formatting masks in our application to support different countries.
Is there a way to write formatting masks so that they include locale, such that we would be allowed to use ONE single mask?
Unless you are using the date functionality in Excel, the easiest way to handle this is to decide on a format and then create a string yourself in that format and set the cell accordingly.
This comic: http://xkcd.com/1179/ might help you choose a standard to go with. Otherwise, clients that open your file in different countries will have differently formatted data. Just pick a standard and force your data to that standard.
Edited to add: There are libraries that can make this really easy for your as well... http://www.libxl.com/read-write-excel-date-time.html
Edited to add part2: Basically what I'm trying to get at is to avoid asking for the asmk and just format the data yourself (if that makes sense).
I recommend doing the following: Create an excel with date formatting on a specific cell and save this for your program to use.
Now when the program runs it will open this use this excel file to retrieve the local date formatting from the excel and the specified cell.
When you have multiple formats to save just use different cells for them.
It is not a nice way but will work afaik.
Alteratively you could consider creating an xla(m) file that will use vba and a command to feed back the local formatting characters through a function like:
Public Function localChar(charIn As Range) As String
localChar = charIn.NumberFormatLocal
End Function
Also not a very clean method, but it might do the trick for you.

Library to discover dates from text?

I need to pull a date out of a string. Since not everyone uses the official ISO format when printing their dates, it is impractical to write a date parser for every possible date format that could be used, and I need to handle as many date formats as possible - I don't control the data and can't expect it to come in a specific format.
This seems like a problem that has probably already been solved ages ago, but my Google-fu is too weak to find the solution. :(
Does there already exist a C++ library that, given a string, will return the month, day, year, hour, minute, second, etc that is referenced in that string, if any?
Pseudocode:
string s1 = "There is an expected meteor shower this Thursday,"
"August 15th 2013 at 4:39 AM.";
string s2 = "20130815T04:39:00";
date d1 = magicConverter(s1);
date d2 = magicConverter(s2);
assert(d1 == d2);
You might use the code from here, but you need to configure a mask, that tells the code which time format is used. If you write a class routine, that takes a mask and a string and gets you out the time and is able to print in any format you like, you should be well prepared. You have to look in more detail, if it also supports Daynames and Monthnames. I got it to work in python with a module providing a function that seems pretty much the same.
For more detail:
Please look at the example 2013-08-03 again. Nobody and as follows no computer is able to tell you if this date belongs to August or April, except of having a mask telling JJJJ-MM-DD or JJJJ-DD-MM. Also this library may tell you only standard masked times. So it might lead you to August in this case. But as you said it can be any date declaration, thus it does not need to follow standards, thus it can also mean March. An other possibility is to tell you about the date from the context (e.g. a table with a column of all te same time formats by looking for the increase (which would also fail if you just look at one day per month for just one year).
Another example... if I ask you 2013-05-04... to which month does it belong? You might tell me... April. I would reply "no, to the 4th of May" and vice versa for May and 5th of April. If you tell me how to solve this puzzle with two possible solutions I would understand your downvote... please think before downvoting someone trying to help you.

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

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.