Saturday, March 31, 2012

String To Date

Hi, I have a vb.net/asp.net 1.1 web application that may be used in
other cultures where dates are formatted differently. I have three
controls (either DropDowns or TextBoxes) one for year, one for month,
and one for day.
I'd like to be able to convert this to a DateTime type of variable and
not have to rely on or find the localization settings.
My idea was to populate the DateTime.Year, DateTime.Month and
DateTime.Day from the controls, (like Date.Year = txtYear.Text) but
those properties are read-only.
I know I could make a string like "12-19-2005" and do a
strDate.ToDateTime but that will break as soon as the application is
used where dd-mm-yyyy is the norm.
So If I have three variables representing year, month, and day what's
the best way to convert to Date without relying on any kind of
localization setting? Thanks!
Mattit works in ASPNET 2.0,
it should work in ASP.NET1.x
Dim MyDate As New DateTime(2005, 12, 19)
Daniel TIZON
MCP - MCSD.NET - MCT
"MattB" <somedudeus@.yahoo.com> a crit dans le message de news:
40osodF1b4pklU1@.individual.net...
> Hi, I have a vb.net/asp.net 1.1 web application that may be used in other
> cultures where dates are formatted differently. I have three controls
> (either DropDowns or TextBoxes) one for year, one for month, and one for
> day.
> I'd like to be able to convert this to a DateTime type of variable and not
> have to rely on or find the localization settings.
> My idea was to populate the DateTime.Year, DateTime.Month and DateTime.Day
> from the controls, (like Date.Year = txtYear.Text) but those properties
> are read-only.
> I know I could make a string like "12-19-2005" and do a strDate.ToDateTime
> but that will break as soon as the application is used where dd-mm-yyyy is
> the norm.
> So If I have three variables representing year, month, and day what's the
> best way to convert to Date without relying on any kind of localization
> setting? Thanks!
> Matt
Daniel TIZON wrote:
> it works in ASPNET 2.0,
> it should work in ASP.NET1.x
> Dim MyDate As New DateTime(2005, 12, 19)
>
Perfect. Thanks!

0 comments:

Post a Comment