Thank you very much to everyone who has helped. See my response to your posts
below.
I checked regional settings via the control panel regional and language
option. It is all in UK.
The web.config has a globalizatoin option of :
<globalization requestEncoding="utf-8" responseEncoding="utf-8"
uiCulture="en-GB" />
I tried using dd\/MM\/yyyy" as date format pattern that is passed to
'ParseExact'.
but it does not compile because a value of date type cannot be converted to
datetime.
I am using VS 2003. I post the code below.
When you say the code that displayys the date do you mean the calendar code
that loads it into the textbox where it is displayed (read only).
If so, here it is:
<p>
<asp:label id="lblDay" runat="server" Height="18px" Width="184px">Assessment
Date:</asp:label>
<asp:textbox id="txtAssessmentDate" runat="server" Width="88px" Wrap="False"
ReadOnly="True"></asp:textbox>
<A
onclick="window.open('../calendar/popup.aspx?textbox=txtAssessmentDate','cal','width =250,height=225,left=270,top=180')"
href="javascript
:;"> <IMG src="../images/SmallCalendar.gif" border="0"></A>
</p>
From the calendar to the textbox:
Protected Sub Change_Date(ByVal sender As System.Object, ByVal e As
System.EventArgs)
Dim strScript As String = "<script>window.opener.document.forms(0)." +
control.Value + ".value = '"
strScript += calDate.SelectedDate.ToString("dd/MM/yyyy")
strScript += "';self.close()"
strScript += "</" + "script>"
RegisterClientScriptBlock("anything", strScript)
End Sub
The date is visible in the textbox whhen I press the next button. This
results in a sub that runs the code below (commented out because I cannot get
it to work).
' Dim dtm As System.DateTime = CDate("24/06/2006")
' Dim assessmentDate As String = dtm.ToString("d") ' although the month is
than given in a single 6
' Dim assessmentDate As String
' assessmentDate = txtAssessmentDate.Text.Trim
' Dim dt As dateTime = System.DateTime.ParseExact(assessmentDate,
"dd/mm/yyyy", Nothing)
'pass module details into the routine to insert it into SQL server.
moduleInsertStatus = clsModules.spModules_Ins(moduleCode, moduleName,
level, courseworks, noOfCourseworks, leader, location, startTimeHours,
startTimeMinutes, endTimeHours, endTimeMinutes, assessmentDate)
spModules_Ins has code to call the stored procedure sql parameters are:
ByVal assessmentDate As System.DateTime
command.Parameters.Add("@assessmentDate", SqlDbType.DateTime, 11)
command.Parameters("@assessmentDate").Value = assessmentDate
"Larry Lard" wrote:
Richiep wrote: 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?
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
When I try it, it does.
The date returned is #12:00:00 AM# but the date I entered into the text box
was 24/06/2006.
Show us the code that displays the date.
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)
That compiles just fine when I paste it into VS2003 and VS2005... I'm
not sure how you're getting those to error.
--
Larry Lard
Replies to group please