Application gets different date format - asp.net

The server where I have deployed my ASP.NET application uses the date format mm/dd/yyyy. So it is expected that when accessing the application, the user should see the date in a calendar control formatted as mm/dd/yyyy.
But on some other machine it shows the date format as dd-mm-yyyy, and with this date format the SQL query crashes with a datetime conversion error.
Can you help me with this? Why does the date format change with the machine?
Thanks.

it changes because of the culture set on the machine, but you can always format the date like this:
string.Format("{0:MM/dd/yyyy}", datevalue);

Related

Asp.net MVC DateTime Culture

I am using my Windows machine in English, and when i looked at the MsSql DB, my date time is in mm/dd/yyyy format.
But i want this format in dd/mm/yyyy.
There is no problem about datepicker that i am using, i can change the input type, but unless i change my culture, i am not able to insert my date fields.
I have already tried to put culture tag into my web.config but still i am not able to insert the date as 29/2/2014. It is accepting only 2/29/2014.
What is the best way to resolve this problem without depending the server language ?

ASP.net Showing just Date (without time)

I am using VS 2010 with SQL Server 2008 R2 Express to develop an ASPX page
In my database there is a column of type Date.
I stored data in dd/mm/yyyy format. Didn't put any time there and it doesn't show any time when I view table data in SQL Server.
But in my aspx page, when I pull data using GridView and SqlDataSource...it shows dd/mm/yyyy hh:mm:ss AM/PM (example- 12/04/2012 12:00:00AM)
Why does it show the time? How can I remove that time part & show just the date ?
Please help
PS: I'm using .net Framework 4.0 and C#
Take a look at that MSDN article.
http://msdn.microsoft.com/en-us/library/az4se3k1.aspx
You need to set up the DataFormatString string with one of the format strings from the link above :)

asp.net + Testing timezone

I am try storing my date values in UTC format into my SQL Server DB and then convert them to local time for displaying, seem to work fine, I can see that my DB date values stored are different(I presume it's converted to UTC already), retrieving it and display is also accurate until I try to test a different timezone by changing it in the Date and Time option(right bottom of Windows time settings in the task bar) so to "migrate" myself. Apparently, the dates still remain as I am in my own country even though the timezone which I changed to has a 3 hrs difference.
Can somehow please advice on a way to test the date display on a different timezone?
Thanks.
Storing date values to SQL Server:
DateTime dateFrom = DateTime.Parse(startDateTime).ToUniversalTime();
DateTime dateTo = DateTime.Parse(endDateTime).ToUniversalTime();
parameters.Add(new SqlParameter("#StartDateTime", dateFrom));
parameters.Add(new SqlParameter("#EndDateTime", dateTo));
Retrive from DB and Display:
DateTime date = DateTime.UtcNow.ToLocalTime();
date = DateTime.Parse(dr["StartDateTime"].ToString()).ToLocalTime();
litDateTimeFrom.Text = date.ToString("dd MMM yy hh:mm tt");
date = DateTime.Parse(dr["EndDateTime"].ToString()).ToLocalTime();
litDateTimeTo.Text = date.ToString("dd MMM yy hh:mm tt");
First thing, I am assuming that you have changed time zone information on the server machine (because that is what will be used in ToLocalTime method). If not then that's what you need to do first for testing.
Secondly, have you tried restarting IIS (or your web application) after changing the system time zone? That is necessary because time-zone information could have been cached within .NET framework (in TimeZoneInfo class).
Said all that, to me, this does not make sense. Typically, time-zone information need to flow from user (client) machine because you want to show user local time (as relevant to his time-zone). So it would mean that you need to figure out the current user's time zone based on a) culture info from browser or b) what is stored in his profile data (perhaps country or actual time-zone) c) similar scheme. Once, user time-zone is known, you can use
TimeZoneInfo class to convert UTC time to corresponding local time.

Date issue in Client(Flex) and Serverside(JAVA) issue

I have a date porblem in flex applications.
while submit the date in flex applcation (28/09/2010 10:00:00 AM) as a string, the date is cobnverted in to Date object inserver side and displayig the result.
But i install the server in other location (Ex:- USA) .Now i am passing the date from india(28/09/2010 10:00:00 AM) But the date in the USA is different. How to convert the date? Conversion should be happen in client side or server side? How the server knows the date which is given by client is the current date?
Thanks,
Ravi
You can save the date as UTC ( universal time ) on the server , and when retrieved on the client use the Date class timeZoneOffset property to set the date to the client's current location

How to store and display date in dd-mm-yy format in Joomla?

I am developing a component in Joomla. Through my component I want to store timestamp to "lastaccessed" field.
My problem is that, if I am simply storing the date, then MySQL is displaying it as "0000-00-00 00:00:00"
I am using the PHP date function like this:
$row->date_lastaccessed=date();
How can I store and retrieve the date in my format (dd-mm-yyyy hh:mm:ss ampm)?
Have you looked at:
http://php.net/manual/en/function.date.php

Resources