On Fri, 6 Jul 2007 16:36:02 -0700, Tisha <(E-Mail Removed)>
wrote:
>Hello,
>I'm trying to select a group of records with an effective date >= Jan 1 of
>the prior year forward to date. So I created a compare date of date - 1
>year. Next, I want to compare this date to the EFFCYMD so I created a ccyy
>date field but the selection criteria fails. The date fields look
>different. How do I compare these fields? Thanks!
>
>SELECT tbl_ZCH.GRP, tbl_ZCH.IDNBR, tbl_ZCH.COMPCD, tbl_ZCH.EFFCYMD,
>tbl_ZCH.CARCD, Year(Date())-1 AS Datecmp, (Mid([effcymd],1,4)) AS Effccyy,
>Right([datecmp],4) AS [Year]
>FROM tbl_ZCH;
>
You're treating the date as a string. IT ISN'T. A Date/Time field is actually
stored as a number, a count of days and fractions of a day since a start
point. The format does NOT change what's stored, just how it's displayed.
To get all records since January 1 of the previous year use a criterion on the
date field
>= DateSerial(Year(Date()) - 1, 1, 1)
John W. Vinson [MVP]
|