tommyf Posted April 10, 2004 Posted April 10, 2004 I have the following cade that takes the date from a calander control and then extracts the required field from a database. Dim fdate As Date Dim fday As Integer fday = fday - Weekday(Me.DateTimePicker1.Value.Date, 0) + 1 fdate = DateAdd("d", +fday, Me.DateTimePicker1.Value.Date) Dim mycommand As New OleDbCommand("SELECT * from tblgym WHERE Gdate = #" & Format(fdate, "G") & "#", MyConnection) Dim MyReader As OleDbDataReader = mycommand.ExecuteReader() MyReader.Read() I have tried to format the date but can not seem to change it Format(fdate, "DD/MM/YYYY") and Format(fdate, "ddmmyyy") but I just get the follwoing error Additional information: Cast from string "DD/04/YYYY" to type 'Date' is not valid. I have also tried to format it in the SQL statement as Format(fdate,"yyyymmdd") as I have done that before in Access but the program breaks on the following line Dim MyReader As OleDbDataReader = mycommand.ExecuteReader() Any Ideas as this is driving me nuts Quote
*Experts* mutant Posted April 10, 2004 *Experts* Posted April 10, 2004 Try this format: "dd/MM/yyyy" Quote
tommyf Posted April 10, 2004 Author Posted April 10, 2004 Thanks mutant that works Why does it have to be MM? Quote
*Experts* mutant Posted April 10, 2004 *Experts* Posted April 10, 2004 Because "mm" represents minutes. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.