Thanks:  0
Likes:  0
Dislikes:  0

# Thread: Code to calculate the no of days between two dates

1. ## Code to calculate the no of days between two dates

can any one please give me code to calculate the number of days between two dates

2. ## Re: Code to calculate the no of days between two dates

write it yourself and we'll check it...

it's not that difficult

3. ## Re: Code to calculate the no of days between two dates

can we try out this way ..

DATE_NOW + ONE_DAY this works so this is just my assumption not much thot on this logic..

Loop starts from i = 1
if Date1 - One_Day = Date 2 then
lr_output message of (number of days is "i")
else
Date1 = Date1 - One_Day
i=i+1
end if
end loop

&gt;&gt;&gt;from date1 - 1,2,3,4 .....days somewhere both dates shud match ...

We Should think of making special THREAD where we can upload this kind of special codes. like Date functions/String replacment functions/ kind of logic codes can be shared.

4. ## Re: Code to calculate the no of days between two dates

[ QUOTE ]
We Should think of making special THREAD where we can upload this kind of special codes. like Date functions/String replacment functions/ kind of logic codes can be shared.

[/ QUOTE ]

5. ## Re: Code to calculate the no of days between two dates

not 100% convinced that will work...

what exactly is DATE_NOW?

you'd need to convert the dates to the same format (I'm guessing it's a number)

if that's the case (and I can't try as I'm at home) I'd convert the dates and subtract one from the other take the absolute result and examine - might be an integer number of days, then again might not be

6. ## Re: Code to calculate the no of days between two dates

[ QUOTE ]
not 100% convinced that will work...

[/ QUOTE ]

Jim, tried implementing my logic just to convince u and it works [img]/images/graemlins/smile.gif[/img]

int i;
char * Date2;
int result;

result =1;

Date2 = "05/13/2010";
lr_save_datetime("%m/%d/%Y", DATE_NOW ,"date1");
//change the date1 format as per the Date2 format entered by user

for (i=0;; i++)
{

if (strnicmp(lr_eval_string("{date1}") , Date2 , 10)==0)

{

lr_output_message("from current Date -%d days is the difference", i-1);
return 0;

}else
{
lr_save_datetime("%m/%d/%Y", DATE_NOW - (ONE_DAY * i) ,"date1");
lr_output_message("%s - %s ",lr_eval_string("{date1}"), Date2);

}

}

******************************
Sai, if you have Date1 as user entered date then try out

a = take difference of today - date1
b = take difference of today - date2

a-b is the differnece of days from UserDate1 &amp; UserDate2

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•
Search Engine Optimisation provided by DragonByte SEO v2.0.36 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.