?
Solved

Format Time

Posted on 2003-03-19
7
Medium Priority
?
192 Views
Last Modified: 2012-05-04
Hi,  I had some problem formating the date in ASP.NET. Here is my code:
     
Dim mydate As DateTime = CDate(kivdate.Text)
Dim test As String = Format(mydate, "dd/MMM/yyyy")

When I input data such as "10/01/03" in the kivdate textbox i would like it to display it as
10-Jan-03 but then i appear as 01-Oct-03. I had already specify the format of the date to dd/mmm/yyy but it is that the data does not format into the type i want.


0
Comment
Question by:austinpeck
  • 4
  • 2
7 Comments
 
LVL 28

Expert Comment

by:iboutchkine
ID: 8166313
Check your Regional Setting in CVontrol panel
0
 
LVL 23

Expert Comment

by:naveenkohli
ID: 8166480
The format of the date you are getting, has nothing to do with any setting in ControlPanel. The format of date is dependent on the culture info of current executing thread. Bydefault most browsers have US as the first language and in web.config the default language is en-us. This results in the type of date format you are getting.
You will have to suply a FormatProvider object when you convert the string to DateTime object.
0
 
LVL 23

Accepted Solution

by:
naveenkohli earned 300 total points
ID: 8166517
You may have to do somehting like this...

DateTimeFormatInfo dtFmt = new DateTimeFormatInfo();
               dtFmt.ShortDatePattern = "dd/MM/yy";
               DateTime dt = Convert.ToDateTime("10/01/03", dtFmt);
               //DateTime dt = DateTime.Today;
               Console.Write(dt.ToShortDateString());

               string strDate = dt.ToString("yyyy-MM-dd");
               Console.WriteLine(dt.ToShortDateString());

               strDate = dt.ToString("dd-MMMM-yyyy");
               Console.WriteLine(strDate);
0
Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

 

Author Comment

by:austinpeck
ID: 8171086
Well your codes seems like Java to me. The languge I am using is ASP.NET VB. Anyway thanks for the solution but i still can't slove this problem
0
 
LVL 23

Expert Comment

by:naveenkohli
ID: 8171197
The sample code is C#, not java.
What is the error that you are still getting? Have you tried using similar code in VB.Net
0
 

Author Comment

by:austinpeck
ID: 8172324
Sorry my progamming languge is not that good. What i did is that i copy the whole chuck of code you provide into my code.
This are the following errors.
1. Name 'DateTimeFormatInfo' is not declared.
2. Name 'Dtfmt' is not declared
3. Name 'dt' is not declared

Since your code is in C# is there anyway that you can help me convert to VB.net?
thanks you.
0
 
LVL 23

Expert Comment

by:naveenkohli
ID: 8173146
For formating info you will need to import System.Globalization namespace in your code. And you will need to remove the Console.WriteLine statements becasue they were for Console app and not for ASP.Net app.
0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question