Day/Night LDR sensing code. What is the correct approach to sampling day/night.

Posting your code would help.

In general I would say that you want to include some lag or dampening in the way that the software wants to react to sensor changes.

One way is to use an averaged value for the sensor reading (say n seconds worth of data, or x readings). Alternatively only add on some fraction (say 30%) of the difference between the current sensor reading and the previous one. Both of these will dampen the changes and should provide smoother changes.

Once you have done this, then set a limit (HI) when the light will switch on and a limit (LO) when the light will switch off, with LO < HI (ie, don't use the same value). This difference will make sure that once the light is on it will need to get a lot less dark before it switches off avoiding the problem that you are seeing with it coming on and off.