Great Ideas. Always Flowing.

We are not happy until you are happy. Client satisfaction guaranteed. Whatever your needs and requirements, we have the skills and resources for the job!

Quick login...


Or... now make it easy with Facebook Integration
Connect via Facebook



Top Sellers

Frustrated over the lack of customization for your user's registration fields? Dynamically setup your DNN Portal with custom registration fields, layout, questions, and other core integration options......

Ultra Video Gallery is a brother product of Ultra Media Gallery, UVG allows you to upload videos in various format and automatically encode them to flv or H264 format, you also can add videos from internet or record live videos from your webcam.

Build high performance, completely customizable data-entry forms and views driven by your DNN and external databases. New built-in tools make it a snap to quickly create data entry forms, data views, and even database tables. Plus, add your own HTML, CSS, Javascript, SQL commands, stored procedures,

The most advanced DotNetNuke shopping cart on the planet. Easy to use e-Commerce, Secure Shopping Cart Software and SEO friendly. B2C / B2B Ecommerce Sites.

One stop solution for events calendar and events registration! FREE DOWNLOAD is available now!

Subtracting two dates with datediff
Last Post 10-26-2010 10:14 AM by Ryan Bakerink. 3 Replies.
AddThis - Bookmarking and Sharing Button Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
Jeff WingoUser is Offline
skipping stones
skipping stones
Posts:7
Avatar

--
10-15-2010 05:44 AM
    Hi,

    I have a form with two fields, Departure Date and Return Date.  I want to calculate the duration of the trip in days.

    I created a hidden field to contain the value for Duration.

    I went to the Advanced Field Options / Default Value for Duration, and entered the following SQL Statement:

    select CAST(datediff(d, '$(datefielddeparture)', '$(datefieldreturn)') as varchar(10)) as DefaultValue

    I can get this statement to run fine in SQL Server Management Studio by declaring the variables, but when I convert it for inclusion in Dynamic Forms it doesn't return a value.

    Here is the SQL Snipit I used to build the statement and test it is working:

    declare @datefielddeparture date;
    declare @datefieldreturn date;
     
    set @datefielddeparture = '2010-10-15';
    set @datefieldreturn = '2010-10-29';
     
    select  CAST(datediff(d, @datefielddeparture, @datefieldreturn) as varchar(10))
     as DefaultValue

    Any help would be greatly appreciated.
    ChuckUser is Offline
    river guide
    river guide
    Posts:157
    Avatar

    --
    10-15-2010 07:41 AM
    Posted By Jeff Wingo on 10/15/2010 7:44 AM
    I created a hidden field to contain the value for Duration.

    I went to the Advanced Field Options / Default Value for Duration, and entered the following SQL Statement:

    select CAST(datediff(d, '$(datefielddeparture)', '$(datefieldreturn)') as varchar(10)) as DefaultValue


    Hi Jeff,
    I dont think you can run SQL statement if its based on the data values coming from textboxes if that is how you set it up.  I think I read it, they didnt allow this option due to SQL Injection.

    Another alternative is to get your answer using Client Side Event Javascript option in your question.



    Jeff WingoUser is Offline
    skipping stones
    skipping stones
    Posts:7
    Avatar

    --
    10-18-2010 06:18 AM
    Chuck,

    Thanks for the insight.  After reading your post I had a little deeper look around and was able to sort out a solution.  I thought I would post it hear as it seems to be a fairly common business problem which one might need to solve.

    I added the following Java Script to Module Configuration / Custom Java Script File / Initial Java Script :

    $(parkingDuration) = Math.ceil(((Date.parse($(datefieldreturn)) - Date.parse($(datefielddeparture))) / (((1000*60)*60)*24)))

    I want to calculate the duration between a departure date and a return date for a trip.  I used the Date.parse function to convert each date to milliseconds.  Once the data is in milliseconds it is easy to just subtract the two numbers.  The only trick is once the milliseconds are subtracted, you have to divide it by the number of milliseconds in a day which is 1000 * 60 seconds * 60 minutes  * 24 hours.

    I have a page where a person specifies the departure and return dates, and then hits a button to display the price quote.  The button click redirects to a sub page which displays the quote.  This sub page executes the above java script on page load and does the calculations.

    Thanks again for the help, I hope sharing this will help save someone else some time in the future.

    Regards
    Jeff Wingo
    http://www.BorngeTech.com
    Ryan BakerinkUser is Offline
    river guide
    river guide
    Posts:1900
    Avatar

    --
    10-26-2010 10:14 AM
    Hello Jeff,

    I'm glad to see that you've found a workaround for this issue you were running into.

    Chuck, thank you for providing you knowledge and time to assist Jeff.

    If either of you have any questions please let us know.

    Thanks,

    Ryan
    You are not authorized to post a reply.


     
     

    Join our mailing list...

    Get current news and events the easy way
    Subscribe Me

    Recent Blogs...

     
    Copyright 2005 - 2011 by Data Springs, Inc.
     
  • film izle
  • 720 izle
  • film
  • sinema izle
  • film makinesi
  • T�rk�e dublaj film
  • film izle
  • film izle
  • baglan film izle
  • sinema izle
  • 1080 film izle
  • film mercegi