Cedwin
Cedwin

Reputation: 1

Convert DateTime afterusing GetDate?

This is for SI am trying to convert a DATETIME so it formats as "mm/dd/yy"

I need the "LastPaymnt_Date" to be greater than or equal to 31-which I've successfully set up below. Any help would be appreciated

This is what I have; it generates an "Incorrect syntax near CONVERT" error

SELECT D1_Name AS 'Debtor Name', FILENO, Balance, LPaymnt_Date AS 'Last Payment Date'
FROM MASTER
WHERE LPaymnt_Date>=GETDATE()-31 
CONVERT(varchar(20), GETDATE, 101
AND(Forw_no>= 340 AND Forw_no <=348)
OR Forw_no =831
ORDER BY D1_Name

Upvotes: 0

Views: 558

Answers (2)

Tanner
Tanner

Reputation: 22733

You have the CONVERT in the WHERE clause. You want it in the SELECT:

SELECT D1_Name AS 'Debtor Name', FILENO, Balance, 
       CONVERT(VARCHAR(10), LPaymnt_Date, 101) AS 'Last Payment Date'
FROM MASTER
WHERE LPaymnt_Date>=GETDATE()-31 
AND(Forw_no>= 340 AND Forw_no <=348)
OR Forw_no =831
ORDER BY D1_Name

See here for more: SQL Server Date Formats

Upvotes: 1

Bassam Mehanni
Bassam Mehanni

Reputation: 14944

SELECT D1_Name AS 'Debtor Name', FILENO, Balance, 
       LPaymnt_Date AS 'Last Payment Date',
       CONVERT(varchar(20), GETDATE(), 101) As FormattedDate
FROM MASTER
WHERE LPaymnt_Date >= GETDATE()-31 
 AND ((Forw_no>= 340 AND Forw_no <=348) OR Forw_no =831))
ORDER BY D1_Name

Upvotes: 1

Related Questions