I have a a postgis table with point geometries and a timestamp column, which has the information when the point was created. This table is already loaded as a layer into geoserver.

So now in Geoserver, I would like to style this layer via SLD, so that the color of the point changes by its age, i.e. the difference between the point's timestamp and the server time.

Lets say red for older than 2 years, yellow for older than 1 year, green for younger than 1 year.

Is there an approach via sld , maybe by using an environment varialble that can solve this requirement?

  • Have you tried creating SLD for all time slots you require? You then can access time slot layer by giving CQL filter. Jan 28, 2016 at 6:12
  • I ran exactly in the same problem. Do you solved it already. I tried it with a dynamic sld with env variables, which works with a static getmap-request, but dynamically with openlayers. docs.geoserver.org/latest/en/user/styling/sld-extensions/…
    – Basti
    Feb 23, 2016 at 7:54

1 Answer 1


The easiest way is to add a filter comparing two dates:


If you want to write one SLD and have it work for ever it's a bit trickier and you need to look at converting your dates into periods, which probably involves the function dateParse and some Maths functions like <ogc:Sub> to handle a year ago. Then you will need an environment variable (or custom function) to get the current date.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.