Subject: Date conversion
Posted By: lily611 Post Date: 11/26/2004 4:33:59 AM
Hi
I have a problom for date conversion. I am entering the date in dd/mm/yyyy format, but when i am retrieving the same date its displaying in mm/dd/yyyy format. How to convert the date in again dd/mm/yyyy format at the displaying in the form. My coding language is C#.

Regards
Lily

Reply By: lily611 Reply Date: 11/26/2004 4:47:31 AM
Hi
Thankx, no need to reply. I got the answer.


Reply By: vinod_pawar1 Reply Date: 11/29/2004 1:41:57 AM
Hi Lily,

I am very sorry, but you should have given answer too in your second post, if somebody comes to see the solution for this problem, he might have got benefited. but instead you just wrote that you got the answer. there are many people visit to this site just to find the answer to their question instead of posting new topic.

Thanks


Vinod Pawar
Software Developer
India
Reply By: jayasankar_m Reply Date: 12/1/2004 12:05:43 AM
hi

         Iam new to .Net.
 one way to change date format might be changing the date format in
the  Control Panel-->regional settings .

Reply By: lily611 Reply Date: 12/3/2004 3:22:12 AM
Hi
This is how i have done

System.DateTime dtdob1=dr.GetDateTime(5);
                string day=dtdob1.Day.ToString();
                if(int.Parse(day)<=9)
                {
                    day="0"+day.ToString();
                }
                string month=dtdob1.Month.ToString();
                if(int.Parse(month)<=9)
                {
                    month="0"+month.ToString();
                }
                int year=dtdob1.Year;

                Label5.Text=day+"/"+month+"/"+year;

Reply By: mordain Reply Date: 12/4/2004 10:54:29 AM
Hi,

The following is probably a better solution.

Use DateTimes own ToString to format the date as follows

string date = dateTimeObject.ToString("dd/MM/yyyy", DateTimeFormatInfo.InvariantInfo);

Note the case of "dd/MM/yyyy".


Reply By: vinod_pawar1 Reply Date: 12/5/2004 11:41:31 PM
Hi there,

There are many ways to achieve the desired format of date and time, only difference is logical.

There is an in-built feature Microsoft has provided in .NET framework called CultureInfo that resides in System.Globalization namespace, which gets rid of all your problems. It not only solves date problem as many have always had in past but also it takes of local currency format, time format etc.

If you want specific date format for a page

just set these two properties of the webform in Design mode using Property Window.

1.Culture
2.uiCulture.

as in India We follow British Date format(i.e. "dd/MM/yyyy"), I'll just set these two properties to "en-GB English (United Kingdom)"

and what else, you have to forget all the additional coding for this page in order to show the local date format.

The Best part of it is, you will not even need to change the date format while inserting it into database, .Net framework is smart enough to take care of it.

here I am putting a link which will give a brief and useful information in this regard.

http://www.c-sharpcorner.com/Code/2004/March/MultilingualAppsInNet.asp




Vinod Pawar
Software Developer
India

Go to topic 23069

Return to index page 697
Return to index page 696
Return to index page 695
Return to index page 694
Return to index page 693
Return to index page 692
Return to index page 691
Return to index page 690
Return to index page 689
Return to index page 688