Link to home
Start Free TrialLog in
Avatar of Zeus2009
Zeus2009

asked on

vb.net date serial

Hi all,

I am using vb2005 CF.net 2, i have come across a problem with dates in different regions.

can someone provide an example of how i can format a date to MM/dd/yyyy no matter what region the mobile device is set to.

Thanks
Zeus
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Use the ToString() method and specify your desired format:

    Label1.Text = someDate.ToString("MM/dd/yyyy")
Avatar of Zeus2009
Zeus2009

ASKER

Hi thanks for the reply,
the issue is i already have the above in my code but when casting from a string to date and it is in a different region to that of the date in the string i get an invalid cast exception.

any ideas

Thanks
Zeus
Use the Convert function
Convert(Date, "date", 103)
where 103 is one of the date formats (the one you need).
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
is there no global way of achieving the convert back to date without knowing the culture?

Thanks
Zeus
Not that I'm aware of...
ok well i am using dates to store files and i load a list of files into a combobox whos names are dates with which the user can choose from.

so i really need to all dates both string and cast to date to be in the same format a more clear explination would be great.

Zeus
ok...what part do you need help with here?
Hi,
ok, the main objective is being able to sort a list of dates in a combobox, the combobox is populated from files stored with a date as there name i.e 07-17-2009, when i get an array of file names i then need to convert them to dates so that i can sort them using a compare function, but the problem being is the application can be any where in the world i.e multiple reginal settings.

further on in the application when the user selects an entry from the combox it will go and get the file pertaining to the item selected.

hope this helps
I think you should use the datatable storing filenames in one column and converted dates to another, corresponding, column. This way, you do not need to convert the dates back to strings. Bind the date column to the combobox and use the string column as the valuefield.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi again,

Thanks for the feedback the piece of code below has done the trick as both idel mind and code cruiser tried to help i will split the points between you both.

Thanks

Zeus

    Dim strDate As String = "07/17/2009"
    Dim dt As DateTime = DateTime.Parse(strDate, New System.Globalization.CultureInfo("en-US", False))
thanks guys
>as both idel mind and code cruiser tried to help i will split the points between you both.
You selected both comments from idle_mind!