Link to home
Start Free TrialLog in
Avatar of awolarczuk
awolarczukFlag for Australia

asked on

convert from date formate mm/dd/yyyy to dd/mm/yyyy

Hi guys when i am doing an sql query  for the date is it comming out with the us formate meaning it wont find the information i am look here is the code can you please help me get it in good old aussie format thanks guys
Private Sub ListView2_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListView2.MouseClick
        Dim rs As New ADODB.Recordset
        Dim sql As String
        Dim datesel As String
        datesel = ListView2.SelectedItems.Item(0).SubItems(1).Text
        sql = "select * from [Student_Outcomes] where [OutcomeDate]  = #" & datesel & "# And [StudentID] = " & TextBox7.Text
        Debug.Print(sql)
        rs.Open(sql, cnn1, ADODB.CursorTypeEnum.adOpenDynamic, ADODB.LockTypeEnum.adLockReadOnly)
        studentnotes.Text = ""
        If Not (rs.EOF And rs.BOF) Then
            If Not IsDBNull(rs.Fields("OutcomeNotes").Value) Then
                studentnotes.Text = rs.Fields("OutcomeNotes").Value
            End If
        End If
        rs.Close()
    End Sub

Open in new window

Avatar of kennethfine
kennethfine

Hi there,

I see you are using VBScript. See this page, esp. under the "international" section. It will walk you through exactly what you need to know:

http://www.codetoad.com/asp/format_date_time.asp

If you need help adapting this to your script, just let me know.

Happy Programming!
Avatar of Wayne Taylor (webtubbs)
Assuming VB.Net, not VB Script, try the below code.

Also, when storing dates into a database, ALWAYS use dd-MMM-yyyy format. This avoids any future problems, and ensures the dates are stored correctly.

Wayne
    Dim datesel As Date
    datesel = Date.ParseExact(ListView2.SelectedItems.Item(0).SubItems(1).Text, _
                              "mm/dd/yyyy", My.Computer.Info.InstalledUICulture)
    Dim Sql = "select * from [Student_Outcomes] where [OutcomeDate]  = #" & _
              datesel.ToString("dd-MMM-yy") & "# And [StudentID] = " & TextBox7.Text

Open in new window

Avatar of awolarczuk

ASKER

yep i am using vb.net, i am pull the data for a converion so it i will mar sure i store it correctly now just to  confirm is there ment to be a dim with the sql there and when i do put that code in it errors when it gets to the _
Yeah, sorry, it should be like this....
Private Sub ListView2_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListView2.MouseClick
        Dim rs As New ADODB.Recordset
        Dim datesel As Date = Date.ParseExact(ListView2.SelectedItems.Item(0).SubItems(1).Text, _
                              "mm/dd/yyyy", My.Computer.Info.InstalledUICulture)
        Dim sql As String = "select * from [Student_Outcomes] where [OutcomeDate]  = #" & _
              datesel.ToString("dd-MMM-yy") & "# And [StudentID] = " & TextBox7.Text
        Debug.Print(sql)
        rs.Open(sql, cnn1, ADODB.CursorTypeEnum.adOpenDynamic, ADODB.LockTypeEnum.adLockReadOnly)
        studentnotes.Text = ""
        If Not (rs.EOF And rs.BOF) Then
            If Not IsDBNull(rs.Fields("OutcomeNotes").Value) Then
                studentnotes.Text = rs.Fields("OutcomeNotes").Value
            End If
        End If
        rs.Close()
    End Sub

Open in new window

ok i have used the code you gave me and for some reason it is changing the date all togeather to another date i have checked the database and where it is getting the data, the date it should be using is 19/06/2007 this is the date in the listview box where it is getting the data (see attached file first image) look at the list view 2nd from the top
the out put i am getting is select * from [Student_Outcomes] where [OutcomeDate]  = #06-01-2007# And [StudentID] = 54

06-01-2007 as the date

some weird is going on here lol
outcome-screen.gif
it seems that the month is just staying as 01 and the day and year is changing fine
Bugger. It's not getting the month value (mm = minutes, MM = month). The date parsing should have looked like this....

    datesel = Date.ParseExact(ListView2.SelectedItems.Item(0).SubItems(1).Text, _
                              "MM/dd/yyyy", My.Computer.Info.InstalledUICulture)

Apologies.

Wayne
shouldnt it be dd/MM/YYY?? as that the format i want to use
ASKER CERTIFIED SOLUTION
Avatar of Wayne Taylor (webtubbs)
Wayne Taylor (webtubbs)
Flag of Australia 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
mate all working now with a combo of what you gave me and a few other things thanks so much for your help

Great to work with thanks so much