[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 204
  • Last Modified:

ERROR: Syntax error converting datetime from character string.

Getting this error: Syntax error converting datetime from character string.  The format in the database is this (and cannot be changed): 20050509172345

I am attempting to select all posts made to a message board for whatever month it currently is.

SELECT *
FROM computerjo.FORUM_MEMBERS
WHERE M_NAME <> 'mpt' AND MONTH(M_LASTPOSTDATE) = MONTH(GETDATE()) AND YEAR(M_LASTPOSTDATE) = YEAR(GETDATE())
0
movoni
Asked:
movoni
1 Solution
 
rafranciscoCommented:
Try this:

SELECT *
FROM computerjo.FORUM_MEMBERS
WHERE M_NAME <> 'mpt' AND
           SUBSTRING(M_LASTPOSTDATE,5,2) = MONTH(GETDATE()) AND
           LEFT(M_LASTPOSTDATE, 4) = YEAR(GETDATE())
0
 
movoniAuthor Commented:
Once again, thank you rafrancisco, for the very quick response :)
0

Featured Post

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Tackle projects and never again get stuck behind a technical roadblock.
Join Now