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 8613039
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T04:46:28+00:00 2026-06-12T04:46:28+00:00

I am currently working on a form in InfoPath where users enter a specific

  • 0

I am currently working on a form in InfoPath where users enter a specific date in a field.

I then want a formula to calculate how many days that remain of the year. I also want to value each day to a cost. Say each day cost 2$ and the entered date is December 29th. I then want the function to return “price: 4$”

  • 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-06-12T04:46:29+00:00Added an answer on June 12, 2026 at 4:46 am

    XPath 2.0 has an awful lot of date/time functions:

    To get the days between the last day of 2012 and the current day, you can use:

    days-from-duration(date("2012-12-31") - current-date() )
    

    If you have an user inputed date $user-date you need to replace current-date() with that $user-date and to construct a date object for the last december day in that year, which you can do like:

    days-from-duration(date(concat(year-from-date($user-date), "-12-31")) - $user-date )
    

    (or use date($user-date), if $user-date is a string)

    And to get the final price string use:

    concat("price: ", 2  *  days-from-duration(date(concat(year-from-date($user-date), "-12-31")) - $user-date ), "$")
    

    XPath 1.0:

    Without date function you need to do all these stupid calculation by hand.

    You need a map mapping the days from each month to the end of the year. Then you can do Map[$month] - $day. (Or use a map mapping the months to the days to the beginning of the year and subtract that from 365, what I do, since I have that map already lying around)

    Now XPath 1.0 does not have maps, but you can simulate one with a string:

     365 - substring-before(substring-after( "1:00, 2:31, 3:59, 4:90, 5:120, 6:151, 7:181, 8:212, 9:243, 10:273, 11:304, 12:334, 13:365", concat($month, ":")), ",") - $day
    

    This works for every non leap year.

    For a leap year, you just use 366 and add 1 to each month after february:

     366 - substring-before(substring-after( "1:00, 2:31, 3:60, 4:91, 5:121, 6:152, 7:182, 8:213, 9:244, 10:274, 11:305, 12:335, 13:366", concat($month, ":")), ",") - $day
    

    To detect the leap year you could do some modulo calculation, it is probably easier to just use a map of all leap years:

    concat("0", substring-before(substring-after("...,2000:1,2004:1,2008:1,2012:1,2016:1,...", concat($year, ":")), ",")) * 1
    

    this returns 1 if the year is a leap year in the range

    Then put it all together:

     ( 365 - substring-before(substring-after( "1:00, 2:31, 3:59, 4:90, 5:120, 6:151, 7:181, 8:212, 9:243, 10:273, 11:304, 12:334, 13:365", concat($month, ":")), ",") - $day)  * ( 1 - concat("0", substring-before(substring-after("...,2000:1,2004:1,2008:1,2012:1,2016:1,...", concat($year, ":")), ",")) * 1)     +     (366 - substring-before(substring-after( "1:00, 2:31, 3:60, 4:91, 5:121, 6:152, 7:182, 8:213, 9:244, 10:274, 11:305, 12:335, 13:366", concat($month, ":")), ",") - $day) * concat("0", substring-before(substring-after("...,2000:1,2004:1,2008:1,2012:1,2016:1,...", concat($year, ":")), ","))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

im currently working on a form field highlighter in jquery and so far it
I'm currently working on a simple form that stores users inputted information to a
I am currently working on a form that displays information about a specific product
I am currently working on a simple form and i want the info to
Currently I am working on a program that lets me handle data in form
I'm currently working on a project involving a form generator. The user can switch
I am currently working on a Log in form but the thing here is
I am currently working on a log in form and I've heard the best
I am currently working on localizing a Form. However I am somewhat confused as
I am currently working on a php/html/javascript project. I have a form where when

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.