Re: ASP.NET web application - date conversions UK date format?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Richiep,


As far as I can see is all your code in my opinion correct, although you are
writting that you retrieve the date as dd/mm/yyyy; If that is true that
means day minutes year.

If your computer is set to UK and not to US, than this is enough to make
from a British date a datetime value.

dim dtm as datatime = CDate("24/06/2006)
To get it back is than
dim str as string = dtm.ToString("d") ' although the month is than given in
a single 6

However be aware that with a Webpage, you cannot be sure what the user has
typed in, if you did not have displayed the patern on that page. As well do
not all server (at least in Holland) have the right country settings and are
often Installed with US settings.

Cor

"Richiep" <Richiep@xxxxxxxxxxxxxxxxxxxxxxxxx> schreef in bericht
news:27ADD6D7-2198-43EB-BCA1-7F057507E849@xxxxxxxxxxxxxxxx
I am trying to get a UK format date of dd/mm/yyyy.

Why does the following subroutine not return a valid date in a web form?

The date returned is #12:00:00 AM# but the date I entered into the text
box
was 24/06/2006.

The other solution I have tried is given by the following two lines that
do
not compile because a value of date type cannot be converted to datetime:

Dim assessmentDate As String = "24/06/2006"
Dim dt As dateTime = System.DateTime.ParseExact(assessmentDate,
"dd/MM/yyyy", Nothing)


Private Sub getDate2()
Dim assessmentDate As Date
Dim MyCulture As New System.Globalization.CultureInfo("en-GB")
Try
assessmentDate =
System.DateTime.Parse(txtAssessmentDate.Text.Trim, MyCulture)
Catch ex As Exception
lblValidAssessmentDate.Text = "Assessment date: not a valid
date
in UK format"
End Try
End Sub


The date is retrieved from my calendar control into the text box ok as
dd/mm/yyyy. Then I want to take it from the textbox and convert it into a
datetime so that I can store it in a SQL server datetime column. Here is
the
parameter being passed into the VB function that calls the store
procedure:

ByVal assessmentDate As System.DateTime,

Here is the SQL parameter:

command.Parameters.Add("@assessmentDate", SqlDbType.DateTime, 11)
command.Parameters("@assessmentDate").Value = assessmentDate

Thank you anyone who helps.

Sincerely,
Richard.




.



Relevant Pages