Date division - why?

Database

Date division - why?

Hey gang,

I'm going through some old code to attempt some basic documentation (whats that I hear you say plus I didn't orginially create it and the person who did has gone walkabout) and I'm questioning the code below. Can anyone explain why you would do this type of division on a date column as its something I haven't seen before. Unless I'm missing a trick or something really obvious me no get it so why o why??

Field: -

Load_Date DATE FORMAT 'YYYY-MM-DD') COMPRESS

Code: -

DELETE FROM Customer_Details_Copy
WHERE Load_date/100 <>
(SELECT Load_date/100
FROM Customer_Details
GROUP BY 1);

Thanks in advance (unles you can't help then well ....... )
2 REPLIES
N/A

Re: Date division - why?

A date field is held as an integer internally, formatted as yyymmdd (yyy is years since 1900, so start of this year is 1110101).

Divide by 100 removes the days, so your code get rid of Customer_Details_Copy rows which have a load date (yyyymm only) different from the load date (year/month) in Customer Details.

You will probably see lots of old code examples of datefld/100 * 100 + 1 - make a date into the start of the month. 

Re: Date division - why?

Thanks good to know.