Last post Nov 15, 2007 01:59 AM by Nai-Dong Jin - MSFT
Nov 09, 2007 04:37 AM|xiadiao|LINK
I have an sql database and using a vb.net codes... Now the .net display my date as MM/DD/YYYY... And dunno what wrong with my brain i change it to a string so can display in dd/MM/yyyy... Now i notice that my codes is too complicated and i hope to change
the globalization so every of my date display as dd/MM/yyyy format... Is this the right way to change?
Step1: Go control panel and change my date display format to UK instead of US
Step2: Change web config file in vb to <globalization requestEncoding="utf-8" responseEncoding="utf-8" culture="en-UK" />
Seeking for ur'll opinion as this is i think a major change cos many dates will be affected in my program (some hidden date in us format and some display dates in string format)...
Q: Is there any thing else i miss out? Need add or change anything for sql database?
Ur advice is my succeed
Nov 11, 2007 05:29 AM|hkhaled|LINK
There is no need for Step1.
you will only need step 2, but your code should look like the following, as there is no culture available by the name of "en-UK", so its equilant for United Kingdom is "en-GB":
Nov 11, 2007 07:38 PM|xiadiao|LINK
thx for replying... wondering if nv use step 1 will comparing of date diff be different... Dun understand? nvm i try 1st
Nov 11, 2007 08:04 PM|xiadiao|LINK
I have a problem when displaying datetime in vb.net... i use this code in label label1.text = today() although it show the date in the format dd/mm/yyyy but when i retrieved it out in 1 of my page which is inside datagrid, it show the time also... for example
i do not want it to show the time...i have this problem whenever i retrieve date out from database... Any idea? I save date in sql database as smalldatetime
Nov 13, 2007 09:24 PM|Nai-Dong Jin - MSFT|LINK
From your description, it seems that you have retrieved the time value into your textbox, and you want to hide the time part of the datatime, right?
If so, I think you can try ToShortDateString() method of your datatime variable. i.e:
DateTime ft = DateTime.Now;
Response.Write(ft.ToShortDateString()); // It will display 2007-11-14.
Nov 13, 2007 11:21 PM|xiadiao|LINK
Sry i use that as an example...I is select * from database and display in grid... So also use this code to select out the datetime value in my database?
Ok i try 1st... Thanks for ur reply
Nov 15, 2007 01:59 AM|Nai-Dong Jin - MSFT|LINK
I is select * from database and display in grid... So also use this code to select out the datetime value in my database?
In that case, you should convert the return from your data filed to a DateTime typed object first, see:
Suppose you have a DateTime typed filed in your database called "date", and then we can use the following code to covert it to a DateTime typed local variable.
DateTime dt = (DateTime)myds.Tables.Rows["date"]; // Retrieve the value from datatable which is a object typed value, just convert it to DateTime type.
this.Label1.Text = dt.ToShortDateString(); // call ToShortDateString method to get the date part of the datetime.
Dim dt As DateTime = DirectCast(myds.Tables(0).Rows(0)("date"), DateTime)
' Retrieve the value from datatable which is a object typed value, just convert it to DateTime type.
Me.Label1.Text = dt.ToShortDateString()
' call ToShortDateString method to get the date part of the datetime.