I am working on a vb.net web application and I am displaying a Gridview with rows containing datetime, the data is coming from database. In my aspx file, within my asp:boundfield I am trying to change the date format (which at the moment is mm/dd/yyyy hh:mm:ss) to "dd MMM yyyy" (no time) and I have tried using the dataformatstring and HtmlEncode="True/False" (both) but still it does not change the date format in the GridView. The code is as shown below -
<asp:BoundField DataField="STF_JOINED" HeaderText="Joined" SortExpression="STF_JOINED" HtmlEncode="False" DataFormatString = "{0:d}" ReadOnly="True">
In the above code I tried to format the date to shortdate for the moment but it didn't work. I would still want the date format to be in "dd MMM yyyy" format.
I have tried a number of solutions from stackoverflow but none of them seem to work for me. Can someone please tell me what I am doing wrong or what I should be doing, by giving a small example code.
You don't need HtmlEncode at all.
For DataFormatString You have to use, for example, {0:dd MM yyyy} or {0:dd.MM.yyyy} beacuse Your database field data type is datetime not date (where dd represent day, MM month and yyyy year. Be aware for MM, if You write mm it's represent minutes).
<asp:BoundField DataField="STF_JOINED" HeaderText="Joined" SortExpression="STF_JOINED" DataFormatString = "{0:dd MM yyyy}" ReadOnly="True">
Tested and working.
You can read more about data format strings here : BoundField.DataFormatString Property
There You can see examples for Standard and Custom format string (links under every table).
Related
I use Vue3DatePicker with 2 dates (range picker). I put a format on the range, but if the format is slightly different it does not work. How can I put a mask/format on it so it automatically adjusts it to the correct format?
For example:
Date 08-02-2023 works. Date 8-02-2023 does not work. 08/02/2023 Also does not work. How can I catch these dates and put them in the right format, so the datepicker works for those inputs?
<Datepicker
:format="'dd-MM-yyyy'"
:model-value="date"
range
text-input
:text-input-options="{ format: 'dd-MM-yyyy' }"
#update:model-value="setDate"
/>
I'm still new at UFT, but I've come across a problem that I haven't been able to figure out. I'm testing the web based portion of our application right now, and there's dates in all kinds of formats (dd/mm/yyyy, MMM d, YYYY, MMM yyyy)
The one I can't seem to convert to a date is (dddd, MMM d, yyyy).
I found this: ' In addition, a long date format is not recognized if it also contains the day-of-the-week string.' on the CDate function page for ADM help.
So I guess my question is, how do I handle this format? Do I remove the first word in the string? Is there another way to do this? - Thanks all for any help
I am working on Crystal report 2013 and I'd like to format the date in crystal report
from
2008-04-27
to
April 27, 2008
what i have tried is this
Right click on the field -> Format Editor
Date and Time tab
Select date/time formatting you desire
but i can't see the date and time tab when i did this. I also use this formula below but no luck.
CSTR({StudentInformation.BirthDay}, "MM dd, yyyy")
Can anyone please help me to solve this. thanks
create a formula for your date and in your formula set it to totext( {StudentInformation.BirthDay}, "MMMM dd, yyyy" ), then add the formula to your report instead of the field
After having my research. This code solve my problem. It converts the string data type to Date and you can now easily format this according to your need.
DateValue({StudentInformation.BirthDay})
I have a textbox for date display which shows the date in this format: 17/04/2012 but I would like to format it to shows up like 'April 17, 2012'. I tried this code
UserForm1.txtDate = Format(Long Date)
which I am getting syntax error from compiler.Can you please let me know how I can do it?
Thanks
there have been couple of posts on this. Culprit seems to be your system date format. Use of short, medium, long formats will change the result when the system settings change.
In US systems mainly it's done as, e.g. Format$(yourdate, “dd/mm/yyyy”)
Where as European systems, e.g. Format$(yourdate, “short date”)
If we look at explicitly defining your format, you are formulating your regional settings!
Good e.g. short date won’t always be mm/dd/yyyy but could be dd/mm/yyyy. That’s the key advantage over actually specifying the format. Simply you can change how you want your date to look like instead of depending on the system (with or without your knowledge).
When we first encountered this, we had some making the VBA apps and sending it over to another in some other place where they have own localized system date format. Your phone rings... ;)
Short/Long Date: Display a date according to your system’s long date format.
Medium Date: Display a date using the medium date format appropriate for the language version of the host application.
In your case you could use,
UserForm1.txtDate.Value = Format$(Date,"mmmm dd, yyyy")
Or to be super-safe,
Dim dtDate as Date
dtDate = DateSerial(Year(Date), Month(Date), Day(Date))
UserForm1.txtDate.Value = Format$(dtDate, "mmmm dd, yyyy")
Hope that helps.
References
I have an issue with date format in my SSRS. I am saving date from DateTimePicker to database. From there I am taking display in my datagridview using following
dgv.items(0,2).value=Format(Cdate(dsSaver.tblInv.rows(0).items(0)),"dd-MMM-yyyy")
This displays it correctly (04-Nov-2011) but when I take date from the same database to my SSRS using
="Dated: " &Format(cdate(Fields!InvDate.Value),"dd-MMM-yyyy")
It displays it like 11-Apr-2011.
I have tested all winforms fare displaying it right but all SSRS are displaying it wrong.
Please advise.
A couple of things are going on here. The date is being saved appropriately but is being displayed incorrectly due to your formatting options. This line is quite problematic:
="Dated: " & Format(cdate(Fields!InvDate.Value), "dd-MMM-yyyy")
CDate takes a value, generally a string, and converts it to a date, which you are then taking and formatting back into a string. Now, by default reports are set to have their Language property set to English (United States) so the CDate function is taking the string representation of the date 04-Nov-2011 to be 04/11/2011 which it is then converting, using the US format of MM-dd-yyyy (not the Pakistani one) into being the date 11-Apr-2011 because it thinks the month comes first.
So, you should change your Language setting of your report to =User!Language so that it supports whatever the user's language is and will format things appropriately. This may be enough to make your expression work.
Regardless, if Fields!InvDate.Value is being supplied as a date field (as it should be) there is no need for the CDate function and this should work:
="Dated: " & Format(Fields!InvDate.Value, "dd-MMM-yyyy")
There is also the FormatDateTime function but unfortunately it doesn't support the format you want to use.
Have you looked at the RDLC options for Formatting a Report: Format the Date?