Results 1 to 3 of 3

Thread: [RESOLVED] Convert.ToDateTime For Different Formats

  1. #1

    Thread Starter
    Hyperactive Member stingrae's Avatar
    Join Date
    Apr 2002
    Location
    Sydney
    Posts
    401

    [RESOLVED] Convert.ToDateTime For Different Formats

    Hi,

    I'm currently working on project where the system is residing in LA, however I am testing it from my office in Rio.

    What I want to do is collect a date from a form (as a string) and then save it in a variable as type DateTime.

    (Please see code below).

    Code:
    public System.DateTime Birthday
    {
    	get
    	{
    		System.DateTime dbBirthday = System.DateTime.MinValue;
    		try
    		{
    			dbBirthday = Convert.ToDateTime(this.txtbxBirthday.Text);
    		}
    		catch 
    		{
    			dbBirthday = System.DateTime.MinValue;
    		}
    		return dbBirthday;
    	}
    	set
    	{
    		this.txtbxBirthday.Text = value.ToString("mm/dd/yyyy");
    	}
    }
    now this code works perfectly well when being called from a PC that is setup with the local settings of an Americn PC, but not with those settings from a Brazilian PC - ie dd/mm/yyyy instead of mm/dd/yyyy

    as we want to make this available to all, i am trying to save the value using the System.Globalization.DateTimeFormatInfo.CurrentInfo object, but to no avail.

    does aybody have any information on how to use these libraries?

    thanks in advance,

    Rodney
    Last edited by stingrae; Jul 29th, 2004 at 04:01 PM.
    "The passion lives to keep your faith, though all are different, all are great" ... Michael Hutchence 1960-1997.

    Windows & Web Developer
    Specialising in Visual Basic .Net & Client Server Programming & Client/Customer Relations Databases
    Sutherland Shire, Sydney Australia
    www.stingrae.com.au
    Developer of Arnold - Gym & Martial Arts Database Management System
    www.gymdatabase.com.au

  2. #2
    Addicted Member
    Join Date
    Jun 2003
    Location
    Birmingham, AL
    Posts
    188
    This is not the most professional way of doing it but why not just rearrange the string.

  3. #3

    Thread Starter
    Hyperactive Member stingrae's Avatar
    Join Date
    Apr 2002
    Location
    Sydney
    Posts
    401
    after about 5 hours of searching Google, i finally found and example of the System.Globalization.CultureInfo object.

    Here is how it works:

    Code:
    System.IFormatProvider dateFormat = new System.Globalization.CultureInfo("en-US", true);  
    
    
    public System.DateTime Birthday
    {
    
    get
    	{
    		System.DateTime dbBirthday = System.DateTime.MinValue;
    		try
    		{
    			dbBirthday = Convert.ToDateTime(this.txtbxBirthday.Text,dateFormat);
    		}
    		catch
    		{
    			dbBirthday = System.DateTime.MinValue;
    		}
    		return dbBirthday;
    	}
    	set
    	{
    		this.txtbxBirthday.Text = value.ToString("MM/dd/yyyy");
    	}
    }
    hope this helps all future readers.
    "The passion lives to keep your faith, though all are different, all are great" ... Michael Hutchence 1960-1997.

    Windows & Web Developer
    Specialising in Visual Basic .Net & Client Server Programming & Client/Customer Relations Databases
    Sutherland Shire, Sydney Australia
    www.stingrae.com.au
    Developer of Arnold - Gym & Martial Arts Database Management System
    www.gymdatabase.com.au

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width