1

My MS Access sql string is:

select billdate from sales where billdate=#27/07/2014#;

This string displays results as: 27/07/2014.

But, if I input

select billdate from sales where billdate=#01/08/2014#;

The string doesn't display any result. But if I substitute billdate #01/08/2014# with #08/01/2014# The string displays results as: 01/08/2014.

In the sales table, the date format for billdate column is Short Date. My system date and time settings are in dd/mm/yyyy format.

I am actually using VB.NET. But the problem persists with Access rather than my VB code. I am using MonthCalendar object.

Kindly provide solution at database level if possible. If it is not possible then only give me the code at coding level.

3
  • Could you show the VB.NET code used to retrieve the record from the sales table. (OleDbConnection, OleDbCommand etc....)
    – Steve
    Jul 29, 2014 at 10:05
  • 3
    Access requires an unambiguous date, I usually go for year/month/day. If there is any confusion, Access will treat a date as American format.
    – Fionnuala
    Jul 29, 2014 at 10:06
  • To avoid culture issues, you should not use the #. Instead, input all dates in your code as NEW DATE(??,??,??)
    – Steve
    Jul 29, 2014 at 14:10

1 Answer 1

0

Try to format your Value in VB.net.

Your string should build like this:

Dim SQL as string = "select billdate from sales where billdate=" & Format(YourDate, "#yyyy\/MM\/dd#")

5
  • 1
    I don't know why, but the code you suggested is actually working. I had always thought for it as a sql statement error. But now since the vb.net code is working... Thanks man.
    – Nitish
    Jul 29, 2014 at 14:49
  • I couldn't mention about the sql query because its very big. Just take a look here if you want.
    – Nitish
    Jul 29, 2014 at 14:50
  • Nice to listen that this helped you. The Access date format is really confusing, that's true.
    – Nik Bo
    Jul 29, 2014 at 14:53
  • select a.billno, a.billdate, a.cid, b.cname, a.slno, a.pid, c.pname, a.qty, c.unit, (a.rate*a.qty)+(a.rate*a.qty*a.vat/100)-(((a.rate*a.qty)+(a.rate*a.qty*a.vat/100))*a.disc/100), a.callstatus, a.remarks,b.ph1,b.ph2,a.duedate from sales a,contacts b, products c where a.cid=b.cid and a.pid=c.pid and a.duedate=#" & Format(MonthCalendar1.SelectionRange.Start) & "# and reorder='Yes';"
    – Nitish
    Jul 29, 2014 at 14:55
  • 1
    This was my code. The sql statement is as you see, very big. But I had problem only with the dates field. Thanks a lot.
    – Nitish
    Jul 29, 2014 at 14:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.