How to format date in a SQL query?

前端 未结 3 868
情书的邮戳
情书的邮戳 2021-01-27 09:50

Hello I\'m using MS JET OLEDB 4.0 on VBA (MS ACCESS)

SQL = \"SELECT COUNT(Date) FROM [Orders] WHERE [Orders].[Date] BETWEEN \" & \"#\" & StartDate &          


        
相关标签:
3条回答
  • 2021-01-27 10:22

    Use Format function.

    SQL = "SELECT COUNT(Date)" & vbcr & _
    "FROM [Orders]" & vbcr & _
    "WHERE [Orders].[Date] BETWEEN #Format(" & StartDate & "], 'MM/dd/yyyy')# AND #Format(" & EndDate & ",'MM/dd/yyyy')#"
    
    0 讨论(0)
  • 2021-01-27 10:25

    Always use ISO date formatting YYYY-MM-DD and you will have no problems. Without formatting.

    0 讨论(0)
  • 2021-01-27 10:41

    I have noticed from the SQL compilation of the query when using Between, that it turns it to MM/DD/YYYY and it did not work till I used Format(startdate, "mm/dd/yyyy"). Please check the snapshop.

    0 讨论(0)
提交回复
热议问题