Using date in a string

craigg3

Board Regular
Joined
Dec 23, 2002
Messages
161
Office Version
  1. 2013
Platform
  1. Windows
Im trying to run a query and would like the user to not have to go through all the steps so im making it to where they can specifiy the date in a cell and then the query will pull based on that date.

Im having problems with:

((employees.date_last_worked>={ts '2018-06-15 00:00:00'}) AND (emp_taxes.tax_authority_type='F'))

The ts '2018-06-15 00:00:00' is the part im having problems with. I need it to look at Sheets("datego").range("Q1").value and grab the date that is within that cell.


I have tried:
GD=Sheets("datego").range("Q1").value
((employees.date_last_worked>=GD) AND (emp_taxes.tax_authority_type='F'))
((employees.date_last_worked>=& GD &) AND (emp_taxes.tax_authority_type='F'))

.... and a few other combinations but cant get it to work. Im sure im not entering things correctly.

Help would be appreciated. Thanks.
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Suppose your querystring is stored in a variable called sSQL and it already contains the SELECT part of the statement, then this appends the criteria to it:

Code:
sSQL = sSQL & " WHERE ((employees.date_last_worked>={ts '" & format(Sheets("datego").range("Q1").value, "yyyy-mm-dd") &" 00:00:00'}) AND (emp_taxes.tax_authority_type='F'))"
 
Upvote 0
Try this SQL string as the query's CommandText:
Code:
    GD = Sheets("datego").Range("Q1").Value
    Dim SQL As String
    SQL = "SELECT xxxx FROM yyyy WHERE " & _
          "((employees.date_last_worked>={ts '" & Format(GD, "yyyy-mm-dd") & " 00:00:00'}) AND (emp_taxes.tax_authority_type='F'))"
 
Upvote 0

Forum statistics

Threads
1,214,590
Messages
6,120,423
Members
448,961
Latest member
nzskater

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top