I am using the Dynamic Data framework with scaffolding. Quite nice for a small home database that I am creating.
I notice though that if I create a field in the database of type 'date' (not datetime) the value is shown in the dynamic data site as a datetime. i.e. as this,
1/1/2010 12:00am
I just want it to display 1/1/2010 as the underlying data type is just a date, and I have no need to store times too.
I have the scaffolding set up, is there some kind of attribute I can use to specify the format?
Use DataTypeAttribute(DataType.Date) as your property metadata annotation.
Related
I have a view created in a drupal 7 to display the data fields from a table in the database and one of the fields is date_entered which is a timestamp. But the data in the timestamp field shows up as same for each record as " 1969/12/31 - 19:33" instead of what's there in the table.
I have tried changing the timestamp format and applying a patch to fix the issue but nothing seems to fix this.
Do u use the date module? It solves all date and timestamp issues.
Found a work around, i created a hidden field using date module and used the default site format to populate the hidden field and used the array while doing the submit db insert which in turn populates the data base table with the current date of submission and used that date field in the view to display the date instead of the complete timestamp.
I'm based in the UK and I'm developing an MS Access 2016 database for an American client.
How can I change the language settings for this database only and not Access in general so, for example in table design view field format options for date appear appear as mm/dd/yyyy, mm/dd/yy etc rather than dd/mm/yyyy, dd/mm/yy?
I know I can format the data post-hoc using SQL or VBA but I'd prefer to set the behaviour as default at the design stage to limit the potential for error.
Many thanks.
Update, here's the options currently presented for the field format:
You can set the Format property of table fields and textboxes to: mm/dd/yyyy
But that will not change the behaviour of, say, DateValue which still will read a date string like "6/7/2016" as 2016-07-06 using your Windows settings.
So the real answer is that you can not. And neither should you need it - if you don't apply custom formats, your database will display dates as m/d/yyyy when reaching your American client.
If you want to see your application in action, install a virtual machine with US settings, and test your application in this environment.
I have an ASP.NET form(MVC3/Razor) and on the the form I want to alter how a date field displays from a datetime field. I.e. in some of the data columns the time is significant and I want the date and time to show, in others it is irrelevant and I just want the date to display. Is this possible?
Thanks in advance
Chris
Two ways: 1) Using a UIHint attribute to tell the field whether or not to render as a Date or DateTime and then having an EditorTemplate to differentiate the two. Or 2) Use the EditorFor extension method and tell it explicitly which EditorTemplate to use.
The same can go for DisplayTemplates when you want to truncate the time.
Here's an example from SO: ASP.NET MVC Editor-Templates/UIHint with parameters
You can use String.Format to format the date and time in exactly the way you want.
string.Format("{0:dd-MMM-yy}", yourDate);
http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx
You can format each appropriate column as you want. For example:
#string.Format("{0:MM/dd/yyyy}",DateTimeField)
and/or
#string.Format("{0:MM/dd/yyyy hh:mm:ss}",DateTimeField)
I am facing an issue in my Flex application.
I am creating some array collections and storing date objects in it.In the later part of the application I will create 'advanceddatagridcolumns' with these array collections as the data sources.
Initially while creating the Array Col , I do have the 'formats' given by user, for each array collection eg. '1995/06/25' but in the later part I have no access to these formats. I want to display this dates in the data grid in same way as the user has specified. Right now, it displays it in the default format 'Sun Jun 25 00:00:00 GMT+0530 1995' instead of '1995/06/25'.
I have a common 'labelFunction' for these advancedatagridcolumns, and thus I can not use the DateFormatter as I 'formatstring' would be different for different columns.
So is there some way to display/retrieve the date in the same format as stored and not in the default way. Or while creating the date object can't I specify that I would always like it to be returned in some desired format.
The Date class in Flex as far, as my experiences go, is not very versatile. My hunch is that this is by no means possible with the regular framework capabilities.
However, if the date does not need to be changed after the user has input it, you might just want to save it as String and only create a temporary ArrayCollection of Dates for displaying them. This way you don't need to worry about the format changing because you're saving the original value.
How are you parsing the dates anyway? I mean that are you finding out the format yourself with RegExps or such, or using the parse method of the Date class?
just create a labelfunction specific to that column only and then you can use the formatstring
I have a table that contains three columns.
"UserId" type-nvarchar
"PostAuthorId" type-nvarchar
"Post" type-text
This table will contain "wall" posts like in facebook for each user's page. I am going to use a gridview on each user's page to display the posts. The issue is I want to display them with the latest(most current) post being first and the earliest post being last.
I have never used autoincrement before and I am not sure if that is the answer. If it is, I do not know how to use it. I thought about adding a date posted column and then ordering by date.
If I end up using the date column, I could also display the date on the post. Is there a way to convert the date to a readable format?
What is the best way of implementing this type of ordering?
If you use AutoIcrement the first record will start with 1 and each record will increment from there. (default setting)
If you want to sort them by newest first do an ORDER BY ID DESC
I would suggest making a column called wallPostID then setting that to AutoIncrement and also your Primary Key
Date Formating:
If you are displaying this data in a gridView
Go to Edit Columns on your grid view
CLick on the Date field under "Selected Fields" on the bottom left
Under "BoundField properties" on the right Go to Data -> DataFormatString
{0:d} will display as 1/1/2010
This site has more info in string formatting
http://msdn.microsoft.com/en-us/library/fht0f5be.aspx
A datetime column would definitely work for something like this. Assuming you are using MS-SQL, you can also attach a default value to the column using a built-in function like GETDATE(). That way, you only have to input the data that matters and the database will take care of adding the datetime column.
For converting a datetime to a readable format try:
DateTime postDate;
string value = postDate.ToShortDateString();
You should always use an ID field that auto increments. Can also be used as your PK
I would suggest the DateTime field rather than the autoincrement simply because it will not only serve as an effective Sort field, it also preserves information that you may well want to display. If you want the most recent first you'll sort using the Date and a "DESC" modifier:
Select ... Order By [Date] DESC;
When you retrieve the data, you can retrieve it as a DateTime and modify it using C#. You can use "ToShortDateString()" as suggested by mdresser if you just wish to show the date or ToString("...") if you wish to show the time as well. You can also use SQL to convert it into a string before retrieving it:
convert(Varchar(10), #mydatetime, 101)
If you look in MSDN you'll see the various conversion codes (101 is the code used above) that can be used to translate the date in various ways.
UPDATE: You may want to use an autoincrementing field for your application for reasons other than your expressed need to sort wall entries. They are easy to use - just mark the field as an Identity if using SQL Server (other DBs are similar). As far as using them in your program, just think of the field as an Int field that you never have to set.
Now, why would you use a auto-incrementing field? Perhaps the most straightforward reason is so that they give you have an easy way to identify each record. For example, if you permit people to alter or delete their wall entries, the auto-incrementing field is ideal as it gives you a way to easily look up each record (each record will be assigned its own, unique value). You might put an "x" next to the record like StackOverflow does and make it a call back with the UID (auto-increment) value. Note that you should set up your primary key on the UID field if you'll be doing this.
Now, if you find them useful for this reason then you could also sort by the UID. I would still store the date so that you can provide Date and Time feedback as to when an entry was made on the wall but this would no longer be your indexed or sorted field.