(XPage/JS svr-side)How to calculate the year, month and day two weeks from today? - xpages

var TODAY_TEMP = #Text(#Year(#Today()))+#Right("0"+#Text(#Month(#Today())),2)+#Right("0"+#Text(#Day(#Today())),2);
I need to calculate two weeks from today, I already get today, but I don't know how to get the date of after two weeks.
So sorry... I'm not familiar with how to write programs on the javascript server-side...

Use the #Adjust function. Example:
#Adjust(#Today(), null, null, 14, null, null, null);

Related

SharePoint Formula: [Created]+60 days = Extension Date (but need it to be a weekday)

I need help with a formula that will add [Extension], a choice field of 30, 45, or 60, to [Created], and return a date [Extension Weekday].
BUT, that future date must be a weekday.
Example: [Created] + [Extension] = [Extension Weekday], but if the result is a Saturday or Sunday, calculate it as the next Monday.
Thanks!
You can use following formula:
=A2+B2+((WEEKDAY(A2+B2,2)=6)*2)+((WEEKDAY(A2+B2,2)=7)*1)
First weekday = 1 = Monday, last = 7 = Sunday. Change WEEKDAY function second parameter if needed.
You might use following functions:
TEXT() : =TEXT(20/02/2020;"dddd") shows the name of that day.
IF(condition;result)
OR(condition1;condition2)
So you'll need something like:
=IF(OR(TEXT(<date>;"dddd")="Saturday";TEXT(<date>;"dddd")="Sunday");"Monday";TEXT(<date>;"dddd"))
The formatting, day naming, ... might be language dependent, so I'll advise you to do some experimenting, but this gives you a start.

Multiple If statements with BETWEEN

I am a little stuck on the middle part of my Excel VBA function. I am attempting to calculate the difference between two dates and show a result if they fall into three parameters.
This is what I have:
=IF(SUM(42370-T4/365)<=4,20,IF(SUM(42370-T4/365)>=5,25,IF(SUM(42370-T4/365)>10,30,"")))
I think I need to throw in an AND function right in the middle there as I am trying to find a date that is >=5 years but less than 10.
So I want to see:
1-4 Years = 20
5-9 Years = 25
10+ Years = 30
I've converted your 42370 to DATE(2016, 1, 1) and used the EDATE function as an accurate method of advancing months and/or years.
=IF(EDATE(T4, 12)>=DATE(2016, 1, 1), "", 20+((EDATE(T4, 60)<DATE(2016, 1, 1))*5)+((EDATE(T4, 120)<DATE(2016, 1, 1))*5))
Fill down as necessary.
The formula will work in order so flip the second if statement around to check if the date is less than or equal to 9 like so:
=IF(SUM(42370-T4/365)<=4,20,IF(SUM(42370-T4/365)<=9,25,IF(SUM(42370-T4/365)>10,30,"")))

Excel split cost figure between months with partial dates

I have a list of cost figures with start dates and end dates which I need to split between months, I have searched for the solution to this problem but cannot seem to find one that will work with partial months i.e.( startdate:01/01/2015 enddate: 15/04/2015 cost:10000) which would leave figures like Jan:2857, Feb:2857, Mar:2857, Apr:1429.
I have been trying to modify this example: http://www.excel-university.com/excel-formula-to-allocate-an-amount-into-monthly-columns/ but having no luck getting the partial months working.
Any suggestions or help would be most welcome. Thanks in Advance
if you calculate it on daily basis, would it be ok? the result would be:
01.01.2015 01.02.2015 01.03.2015 15.04.2015
2.857,14 2.857,14 2.857,14 1.428,57
your daily amount is:
=10.000/(DAYS360(startdate;enddate;TRUE)+1)
(be carefull of true and false argument)
under the dates or instead of 2.857,14 etc. insert the formula:
=IF(DAY("your date")>1;DAY("your date");30) * daily amount
This formula assumes that you want to have 30 days in each month:
=IF(DAY(01.01.2015)>1;DAY(01.01.2015);30)
result = 30
=IF(DAY(15.04.2015)>1;DAY(15.04.2015);30)
result = 15
so if months begins with a date different from the 1st it will give you the number of days.
if you want to match months with your startdate and enddate (if i understood your comment correctly), you could do:
=IF(OR(
AND(MONTH(startdate)=MONTH(your date);YEAR(startdate)=YEAR(your date));
AND(MONTH(enddate)=MONTH(your date);YEAR(enddate)=YEAR(your date))
);"match";"no match")
by this you make sure that month and year correspond.
If you want to get the number of days in a month automatically, you could use:
=DAY(DATE(YEAR("your date");MONTH("your date")+1;1)-1)
but this does not assume anymore 30 days, you can change it with if statement
I hope this helps,
Best - AB

Excel weird timestamp. How to convert it back to normal timestamp?

I'm using Flash and as3 to convert Excel timestamp to normal timestamp, thus - to normal date.
I have this function
public static function dateFromExcel(date:Number):Date {
return new Date(1970, 0, 1 + (date - 25569));
}
This works fine if I need only a correct date (year, month, date). But now I have a time, that is displayed in Excel as follows:
1:00:00
But the real value of the cell is:
1/1/1900 1:00:00 AM
That's a autoformatted by Excel. Now, when I read Excell with as3 code, as with dates, I get decimal number. For this time I get this:
1.0416666666666667
When I run the same function on this decimal number, I get this:
Mon Jan 1 00:00:00 GMT+0200 1900
Which is obviously incorrect.
As I get, with that function I can only work with the date and not the time. Can anyone look at this and figure out, how to get the time to work with this function too?
While I was writting this question, I figured it out myself.
It is documented, that excel timestamp is the total days starting from 1900/01/01.
So this means, that the numbers after the decimal point is the percentage of the one day. For me, I just multiplied that number with the total count of seconds in one day and got the correct time. The function is as follows:
public static function dateFromExcel(date:Number):Date {
var sec_ind_day:Number = 86400;
var secs:Number = sec_ind_day*date%1;
var _d:Date = new Date(1970, 0, 1 + (date - 25569));
return new Date(_d.fullYear, _d.month, _d.date, _d.hours, _d.minutes, secs);
}
So, anyone who got the same issue, this should work fine.

date time conversion

I have 40241 as a date value. Which format is this in?
I think it is in seconds past midnight.
But I need a formula so that I can work out manually and verify!!
Thanks
If it is an Excel datestamp, then it's the number of days since 31st December 1899 (with 1900 treated as a leap year); which puts it as 4th March 2010... unless Excel was configured to use the Mac 1904 Calendar, in which case it's the number of days since 1st January 1904.
How to convert it depends on your preferred scripting language; or whether you can simply use Excel itself, and just set the format mask for that cell to one of the date formats
If it is "seconds past midnight", you can simply do this:
divide by 3600 (seconds in an hour); you get the number of hours;
take the remainder of that division, and divide it by 60; you get the minutes;
the remainder is the seconds.
Example:
40241/3600=11 (641)
641/60=10 (41)
So it is 11:10:41.
By the way, I suppose that it's a time value; if it was a datetime value it would probably be much bigger (like UNIX timestamps) or it would have a decimal part (like, IIRC, OLE dates).
It turns out that it's an Excel date; then, have a look at this KB article, it's all explained in detail; but if you just want to display it correctly, go on the properties of the cell (Ctrl+1) and set its data type to "Date" or "Date/Time" (or whatever it was, I don't have Excel at hand at the moment).
Excel stores dates in an interesting way. I've had this crop up on me too but I never had to move outside Excel so I could just use the format function in Excel.
You can read more here:
http://www.ozgrid.com/Excel/ExcelDateandTimes.htm
http://www.cpearson.com/excel/datetime.htm
Excel saves the date as an integer for the number of days since Jan 1st, 1900
Note: there is a bug in excel so you do the conversion and subtract one. If you see a decimal after it is the time.
Here is some java code to convert it if you want to verify it:
public static Date ExcelDateParse(int ExcelDate){
Date result = null;
try{
GregorianCalendar gc = new GregorianCalendar(1900, Calendar.JANUARY, 1);
gc.add(Calendar.DATE, ExcelDate - 1);
result = gc.getTime();
} catch(RuntimeException e1) {}
return result;
}
I condensed the apache solution for the date without time ( https://svn.apache.org/repos/asf/poi/trunk/src/java/org/apache/poi/ss/usermodel/DateUtil.java )
public static Date parseExcelDate(double date) {
int wholeDays = (int) Math.floor(date);
Calendar calendar = new GregorianCalendar();
int startYear = 1900;
int dayAdjust = wholeDays < 61 ? 0 : -1;
calendar.set(startYear, 0, wholeDays + dayAdjust, 0, 0, 0);
return calendar.getTime();
}
Other thread: Program in Java to convert a date to serial number as done in Excel

Resources