Date format always changeshttp://forums.asp.net/t/1796128.aspx/1?Date+format+always+changesTue, 24 Apr 2012 06:39:31 -040017961284947441http://forums.asp.net/p/1796128/4947441.aspx/1?Date+format+always+changesDate format always changes <p>Hi all,</p> <p>I want to ask, I want to read the date from database, but everytime I read from the database for the first time it always shows mmddyyyy format. if I go to then next page and back to first page the format changes to ddmmyyyy (this is what i want). Any solution to this problem? The date save in database with this format &quot;2012-04-23 00:00:00.000&quot;.</p> 2012-04-24T01:55:59-04:004947556http://forums.asp.net/p/1796128/4947556.aspx/1?Re+Date+format+always+changesRe: Date format always changes <p>Hi andre</p> <p>Suppose,The date you read from database is with the format&nbsp;<span>&quot;2012-04-23 00:00:00.000&quot;.</span></p> <p>just take the variable of datatype DateTime and store this value in that variable.Then when you are reading the date you can change the</p> <p>format as per your convinence.</p> <p>string strcon = ConfigurationManager.ConnectionStrings[&quot;con&quot;].ConnectionString;<br> SqlConnection conn = new SqlConnection(strcon);<br> conn.Open();</p> <p>string strdate=&quot;select date from tablename&quot;;</p> <p>SqlCommand query = new SqlCommand(strdate, conn);</p> <p>String date=cmd.ExecuteScalar();</p> <p>DateTime datetime = Convert.ToDateTime(date.ToString());</p> <p>String datetime1 = datetime&nbsp;.ToShortDateString();<br> Char[] sep = { '/' };<br> String[] arr = datetime1&nbsp;.Split(sep);</p> <p>String mmddyyyyformat=arr[1].ToString() &#43; &quot;-&quot; &#43; arr[0].ToString() &#43; &quot;-&quot; &#43; arr[2].ToString();</p> <p>string ddmmyyyyformat=arr[0].ToString() &#43; &quot;-&quot; &#43; arr[1].ToString() &#43; &quot;-&quot; &#43; arr[2].ToString();</p> <p>Response.Write(mmddyyyyformat.ToString());</p> <p>Response.Write(ddmmyyyyformat.ToString());</p> <p></p> <p>Here</p> <p>arr[0].ToString() refers to date part&nbsp;of the complete date.</p> <p>arr[1].ToString() refers to month part&nbsp;of the complete date.</p> <p>arr[2].ToString() refers to year part of the complete date.</p> <p></p> <p>Hope this will help you.</p> 2012-04-24T04:28:16-04:004947781http://forums.asp.net/p/1796128/4947781.aspx/1?Re+Date+format+always+changesRe: Date format always changes <p>Hi Andre,</p> <p>Can you please try the following <a href="http://www.kodyaz.com/articles/sql-format-date-format-datetime-t-sql-convert-function.aspx" target="_blank"> SQL Convert DateTime</a> operation. If you check the given reference link, you will see that the convert options 3 and 4 will also work for your case just like option 5 in the below example.</p> <pre class="prettyprint">declare @dt datetime = getdate() select @dt, replace(convert(varchar(20),@dt,5),'-','')</pre> <p><br> I hope that helps,</p> 2012-04-24T06:39:31-04:00