dev.kanngard.net make sure you visit my new blog at: johankanngard.net

Short tip: Creating a W3CDTF date in @Formula

by Johan Känngård / [@Formula] / 2003-01-29 / #58


To create a date time in the W3CDTF format (used in RSS feeds), the following @formulas could be used, and will produce something like "2003-01-21T00:03:04+01:00".

Update: John Marshall kindly gave me a fix for the formula to handle the time zones better. This is the revised formula:

t:=@Created; 
y:=@Right("00" + @Text(@Year(t)); 4); 
m:=@Right("0" + @Text(@Month(t)); 2); 
d:=@Right("0" + @Text(@Day(t)); 2); 
s1:="-"; 
s2:=":"; 
h:=@Right("0" + @Text(@Hour(t)); 2); 
mm:=@Right("0" + @Text(@Minute(t)); 2); 
s:=@Right("0" + @Text(@Second(t)); 2); 
zone:=@Integer(0-@Zone(t)); 
z:=@If(zone > 0; "+"; zone < 0; "-"; "Z") +
@If(zone=0; ""; @Right("0" + @Text(zone); 2) + ":00"); 

y + s1 + m + s1 + d + "T" + h + s2 + mm + s2 + s + z;