Date format in SQL stmnt

D

Dave

Hi

I am having a problem with a date foemrat in a SQL Stment.

My code is

Dim strFormattedDate As Date

strFormattedDate = Format(dteDayToCompare, "mm/dd/yy")

rsDate.Open "SELECT TimeHoursWorkedDate FROM tblTimeHoursWorked WHERE
EmpID = " & EmpID & " AND TimeHoursWorkedDate = #" & strFormattedDate
& "# ORDER BY TimeHoursWorkedDate", gstrEmpDataCon, adOpenKeyset,
adLockPessimistic
 
R

Rick Brandt

Dave said:
Hi

I am having a problem with a date foemrat in a SQL Stment.

My code is

Dim strFormattedDate As Date

strFormattedDate = Format(dteDayToCompare, "mm/dd/yy")

rsDate.Open "SELECT TimeHoursWorkedDate FROM tblTimeHoursWorked WHERE
EmpID = " & EmpID & " AND TimeHoursWorkedDate = #" & strFormattedDate
& "# ORDER BY TimeHoursWorkedDate", gstrEmpDataCon, adOpenKeyset,
adLockPessimistic

If you want the value to stay formatted use a string variable, not a datetime
variable. DateTimes have no format.
 
J

John W. Vinson

Hi

I am having a problem with a date foemrat in a SQL Stment.

My code is

Dim strFormattedDate As Date

strFormattedDate = Format(dteDayToCompare, "mm/dd/yy")

rsDate.Open "SELECT TimeHoursWorkedDate FROM tblTimeHoursWorked WHERE
EmpID = " & EmpID & " AND TimeHoursWorkedDate = #" & strFormattedDate
& "# ORDER BY TimeHoursWorkedDate", gstrEmpDataCon, adOpenKeyset,
adLockPessimistic

Dim it as String rather than as Date. The Format() function returns a string
result, and you need to concatenate a string into the SQL string.

Note that "having a problem" without indicating the nature of the problem or
the error message you're getting is a bit of a barrier toward getting an
answer.

John W. Vinson [MVP]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top