Format Time

Posted on 2003-03-19
Medium Priority
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.

Question by:austinpeck
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
LVL 28

Expert Comment

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

Expert Comment

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.
LVL 23

Accepted Solution

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;

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

               strDate = dt.ToString("dd-MMMM-yyyy");
Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments


Author Comment

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
LVL 23

Expert Comment

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

Author Comment

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.
LVL 23

Expert Comment

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.

Featured Post

Stack Overflow Podcast - Developer Story

Welcome to the Stack Overflow podcast recorded Thursday July 20 at Stack Overflow Headquearters in NYC. Your hosts today are podcast regulars Jay Hanlon, David Fullerton, and Ilana Yitzhaki, plus the quite irregular Matt Sherman (Stack Overflow Engineering Manager extraordinaire)

Question has a verified solution.

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

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

762 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