Symfony 2.1. How can I display a single_text time field in 12 hour am/pm format? - symfony

I have a time field on my form with widget set to 'single_text'.
My US users will want 12 hour am/pm format.
http://symfony.com/doc/current/reference/forms/types/time.html#widget
Although it's not entirely obvious, that accepts an input of 2:15pm but if the form returns because of a validation error on another field or is later opened to edit an existing record then it displays 14:15 which of course is correct but is probably off-putting.
How do I get it to display 2:15pm? I don't see an option to do that.

Well, this turns out to be harder than it should be. The problem is that the Time form type does not allow you to specify a format like the Date form type does and the format it uses is H:i. Yes, 24-hour format :-(
So, the only solution is to build your own form type which uses the h:i format. You can find instructions for how to build your own form type here:
http://symfony.com/doc/2.1/cookbook/form/create_custom_field_type.html
Then you can use the Time form type as the base for your form type and just change the format it uses. The Time form type can be found here:
/Symfony/Component/Form/Extension/Core/Type/TimeType.php

Related

How to change date format in Email Template of Dynamics365?

I want to get the date in this format -
MM-dd-yy.
For example: 10-12-23
I'm writing this code but don't getting the desired solution -
{<entity_name>:<attribute>/#date;} Check-In Link
What should I write in the date part?
I'm afraid the only way to make it work is to set the user's locale to a locale that uses MM-dd-yy format.
Alternatively, it's possible to create a custom string field, populate that field with a properly formatted date and use the value of it in your template.

Get Short Date Format/Style/Structure

Suppose my system date is 2014-02-10 & I have published my app on Internet Information System. Now Using DateTime.Now.ToShortDateString method I can get date like 2014-02-10, but how can get pattern/style/structure (e.g yyyy-MM-dd) for date? It should be irrespective of current culture.
IF I change date to 10-Feb-2014, then I should get dd-MMM-yyyy.
What's the solution? Thanks in adv..
Ah, I see. I thought you were saying that you wanted to format a date value but it seems that you're saying that you actually want the format string. In that case, you need to use get an appropriate DateTimeFormatInfo object and get its ShortDatePattern property. You can use System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat or System.Globalization.CultureInfo.InvariantCulture.DateTimeFormat to get that DateTimeFormatInfo.

Google Docs Forms - need Pre-fill Date & Time Entry with current date and current time

Google Forms I need Pre-filled current Date & current Time Entry in date and time fields of my google form. How to do it
My solution is to make the Date field optional. The default is to assume the todays date which is what you get from the timestamp field. In case it needs to be anything else you can enter it manually.
A simple code-free solution is to make separate sections in your form and use the feature that routes users to different sections based on responses. The first section asks whether the form is for the current date/time. If yes, you use the timestamp as the date and time and route the user to the main section with your questions. If not, route them to a section to set the date and time, and then after that route them to the main section.
2023 Solution
-Google Forms has updated how dates are passed through URL parameters.
Instead of passing each component of a date as a separate param, you now pass them using the same syntax as all other fields using the YYYY-MM-DD format for your date value.
Here is an example URL:
`https://docs.google.com/forms/d/e/${formId}/viewform?usp=pp_url&entry.${dateEntryFieldID}=${YEAR}-${MONTH}-${DAY}`

How do you pass a date value to BIRT report via querystring

I have made a static html page (called start.jsp) containing a form where the user select 2 date ranges and this form has date pickers for those text boxes. When the user submits
the form, it should take them to the BIRT report that I have designed. It SHOULD
pass the 2 parameters that my report needs (start date and end date).
Here is the querystring that gets appended to the URL
birt-viewer/run__report=Business_Activity_Monitoring.rptdesign &FilterStartDate=2000-01-01&FilterEndDate=2009-01-01
I get an invalid date error:
org.eclipse.birt.report.exception.ViewerValidationException: The parameter "FilterStartDate" is invalid. The value "06-08-2010" is invalid with the type "dateTime".
How is it that if I remove the querystring completely, then BIRT will prompt me to enter the
start date and end date (screenshot attached).
I enter the exact same data that the form tries to send and it works!?
This proves that my date string is correctly formatted but yet it will not accept them if they
are sent to the BIRT report via the querystring? Seems like it has a problem with the
fact that its a string in the first place.
I have correctly set up these report parameters in my BIRT report. I have also tried changing them
by specifying the "Format as" value to be a "custom" YYYY-MM-dd but this didnt work.
Is it even possible to send date parameters to a birt report via querystring?
Im guessing the solution will involve converting these strings to dates within the birt report's "script" tab.
but I dont know how to access querystring variables from here or how to set report
parameter variables.
Thanks
-Tommy
Your report parameter probably has a data type of "DateTime". As such your passing of just the date is not sufficient. When you use the OOTB parameter request pages this is accounted for under the covers. Either change your parameter data type to "Date" or append a time signature to your parameter being supplied to the report via your page (i.e. 2009-01-01 00:00:00). Either approach should do the trick.
Good Luck!
The following is the format BIRT appears to use for validation of parameters:
DEFAULT_DATETIME_FORMAT = "yyyy-MM-dd HH:mm:ss.SSS"
So if you pass in date/time as it should work
&mydate=2009-11-22 00:00:00.0
If the start date parameter you are passing is 2000-01-01, why is it giving you an error message saying 06-08-2010 is invalid? It looks as though the date parameter is being set elsewhere within the report, either as a default value or possibly within an event script.
Check your date format; remember that MM is used for month and mm for minutes.
Also check this solution, found at the Eclipse Community Forums:
Try this in the URL:
&mydate=22/11/2009&__islocale=mydate
Replace mydate with your parameter
name. The __isLocale parameter
specifies that the parameter has been
localized.

How to trim datetime string to its minute in GridView?

I have bound fields in GridView to some dateTime property of data objects. The fields are displayed to the seconds level. It looks like 2009-2-3 18:00:00 PM.
I just want it displayed to the minutes, e.g 2009-2-3 18:00.
What is the best way to do this?
Edit:
I find use DataFormatString="{0:g}" is fine for me.
The format is 2009-2-3 6:00 PM.
Although you have found a solution, here's some additional information:
You can find a list of all standard date and time format strings (such as "g") on this page in MSDN: Standard DateTime Format Strings.
And if do not want to use one of the predefined formats, there is also a page about Custom Date and Time Format Strings. For example, to get a date exactly in the format you used in your question ("2009-2-3 18:00") you could use the format string "yyyy-M-d HH:mm".
Before using a custom format string, remember that using the standard (predefined) format strings has the advantage that it automatically takes into account the current culture (regional settings). So if you want to display the date to users, probably a predefined format will be the better choice.

Resources