Click here to Skip to main content
15,921,716 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi all,

my PC date settings is dd/mm/yyyy and my asp.net application is working fine regarding searching by date or inserting or updating.

but when i uploaded my website to my host which its date format is mm/dd/yyyy.

all my works destroyed because for example i can't insert 19/08/2015 which will cause error or even in querystring

for example "mypage.aspx?Date=19/08/2015" will cause error too. how can i make the inserting(19/08/2015) and selecting by date working ??

i want to insert 19/08/2015 to my table which causes error in formview





thanks
Posted
Comments
Maciej Los 19-Aug-15 16:01pm    
The date setting on local machine is not important! The way you save data into database is very important! Please, improve your question.

1 solution

Always use explicit, non-ambiguous formats. So rather than adding your Date param like;

C#
& "Date=" & dt.ToString()


use a specific format

C#
& "Date=" & dt.ToString("yyyy-MM-dd")


When you read the param from the querystring convert it from that format

C#
DateTime dt;

DateTime.TryParseExact(Request.QueryString["Date"], "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None, out dt);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900