Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 952047
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T23:49:49+00:00 2026-05-15T23:49:49+00:00

using xslt how do i test if a date was within the last (say)

  • 0

using xslt how do i test if a date was within the last (say) 15 days?

input:

  • date in format dd/mm/yy
  • X number of days

output:

  • if the date occured within X days of now

eg recent(’02/07/10′,30) would return true iff 02/07/10 was 30 days in the past

some steps i got:

main func

    <xsl:function name="custom:monthtodays">
    <xsl:param name="date"/>
    <xsl:param name="daysago"/>
    <xsl:variable name="daycountnow" select="year-from-dateTime(current-dateTime())*365+day-from-dateTime(current-dateTime())+custom:monthtodays(month-from-dateTime(current-dateTime())" />
    <xsl:variable name="datedaycount" select="numeric(substring($date,1,2))+numeric(substring($date,7,2))*365+custom:monthtodays(numeric(substring($date,4,2)))" />
    <xsl:value-of select="$daycountnow - $datedaycount - $daysago > 0"/>
</xsl:function>

helper func

 <xsl:function name="custom:monthtodays">
    <xsl:param name="month"/>
    <xsl:choose>
      <xsl:when test="$month =1"> <xsl:value-of select="0"/> </xsl:when>
      <xsl:when test="$month =2"> <xsl:value-of select="31"/> </xsl:when>
      <xsl:when test="$month =3"> <xsl:value-of select="59"/> </xsl:when>
      <xsl:when test="$month =4"> <xsl:value-of select="90"/> </xsl:when>
      <xsl:when test="$month =5"> <xsl:value-of select="120"/> </xsl:when>
      <xsl:when test="$month =6"> <xsl:value-of select="151"/> </xsl:when>
      <xsl:when test="$month =7"> <xsl:value-of select="181"/> </xsl:when>
      <xsl:when test="$month =8"> <xsl:value-of select="212"/> </xsl:when>
      <xsl:when test="$month =9"> <xsl:value-of select="243"/> </xsl:when>
      <xsl:when test="$month =10"> <xsl:value-of select="273"/> </xsl:when>
      <xsl:when test="$month =11"> <xsl:value-of select="304"/> </xsl:when>
      <xsl:when test="$month =12"> <xsl:value-of select="334"/> </xsl:when>
    </xsl:choose>
  </xsl:function>

but this doesnt take account of leap years and the like … surely there is a betterway?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T23:49:50+00:00Added an answer on May 15, 2026 at 11:49 pm

    Here is one way you could do it in XSLT 1.0. As you are using .Net 4.0, you should be available to use the microsoft extension function, and write your own (javascript) function to do the date difference.

    Here is the transformation. Note the JavaScript function is quite crude, and assumes the date is in DD/MM/YY format:

    <?xml version='1.0'?> 
    <xsl:stylesheet version="1.0" 
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
        xmlns:msxsl="urn:schemas-microsoft-com:xslt" 
        xmlns:user="http://mycompany.com/mynamespace"> 
    
    <msxsl:script language="javascript" implements-prefix="user"> 
    function datecheck(dateString)  
    { 
        // Get today's date
        var today = new Date();
    
        // Clear down any time portion
        today.setHours(0);
        today.setMinutes(0);
        today.setSeconds(0);
        today.setMilliseconds(0);
    
        // Length of day in milliseconds
        var one_day = 1000*60*60*24;
    
        // Convert date string into a date
        var day = parseInt(dateString.substring(0, 2), 10);
        var month = parseInt(dateString.substr(3, 2), 10);
        var year = 2000 + parseInt(dateString.substr(6, 2), 10);
        var date = new Date(year, month - 1, day);
    
        // Get date difference
        var diff = Math.ceil((today.getTime()-date.getTime()) / one_day);
        return (diff &lt;= 30);
    } 
    </msxsl:script> 
    
    <xsl:template match="/*"> 
       <xsl:value-of select="user:datecheck(string(.))"/> 
    </xsl:template> 
    
    </xsl:stylesheet> 
    

    When you apply it on this input (assuming today is 23/07/2010)

    <date>02/07/10</date> 
    

    You should get the return value of true

    When you apply it on this input

    <date>02/06/10</date> 
    

    You should get the return value of false

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.