XSL template for adding days

November 6th, 2008 | Categories: SharePoint, XSLT

I can’t believe it’s so complex to add couple of days to a certain date. I needed an XSLT way of calculating dates with input parameters for date (format YYYY-MM-DD) and number of days (number). I know, some of you say use EXSLT. After not getting it to work, I’ve decided to do my own version.

Please note that this template is not for calculating more than one month (for example to add 50 days. And date has to be in ISO format (YYYY-MM-DD). It can be a starting point for your modifications and needs to work with dates.


    
    
    
    
    
    
        
            
                
                    01
                    02
                
            
            
                
                    02
                    03
                
            
            
                
                    03
                    04
                
            
            
                
                    04
                    05
                
            
            
                
                    05
                    06
                
            
            
                
                    06
                    07
                
            
            
                
                    07
                    08
                
            
            
                
                    08
                    09
                
            
            
                
                    09
                    10
                
            
            
                
                    10
                    11
                
            
            
                
                    11
                    12
                
            
            
                
                    12
                    01
                
            
        
    
    
        
            
            
        
    
    
        
            
                
                    
                    
                
            
            
                
                    
                    
                        
                            
                                
                            
                            
                                
                            
                        
                    
                
            
            
                
                    
                    
                
            
            
                
                    
                    
                
            
            
                
                    
                    
                
            
            
                
                    
                    
                
            
            
                
                    
                    
                
            
            
                
                    
                    
                
            
            
                
                    
                    
                
            
            
                
                    
                    
                
            
            
                
                    
                    
                
            
            
                
                    
                    
                
            
        
    
    
    -
    
    -
    0
    

Usage:

Copy-paste the upper code to the end of your XSL stylesheet (after the last tag in your data view. Then in your data view you can call the template.




This will return five days from the created date.

There probably IS a better way, I just couldn’t find it. 🙂

Oznake ponudnika Technorati: ,,