Get Date x number of days before current Date
How do you subtract x number of days from a Date object?
Is there a better way than
int x = 28; // number of days
long minisPerDay = 24 * 60 * 60 * 1000;
Date newDate = new Date (oldDate.getTime() - (x * minisPerDay );
> How do you subtract x number of days from a Date object?
Calendar c = Calendar.getInstance();
c.setTime(yourDateInstance);
c.add(Calendar.DATE, -x);
Calculating Java dates: Take the time to learn how to create and use dates
Working in Java time: Learn the basics of calculating elapsed time in Java
Good luck! :o)
~
Similar Messages
-
Extract data on report between last 30 days from current date.
Hi Experts,
Ealrier i had provided user promt to select the date range, now i need to schedule the report for this i have to set the date between last 30 days from current date.
How can i add this in formaula on record selection.
before:
{pm_process.pm_creation_date} in {@Start Date to UTC} to {@End Date to UTC}
I tried:
{pm_process.pm_creation_date} in CurrentDate() - 30 to CurrentDate()
But this is diplaying me only data of 30th date from current date.
Please advice.Hi Brian,
Thank you!
1. I have not created any function for {pm_process.pm_creation_date} in [CurrentDate() - 30 to CurrentDate()] i am just adding this on Record Selection and its not helping.
2. {pm_process.pm_creation_date} in Last30Days; this is throwing below error.
please advice what to be done? -
Find Exact number of days between two dates
How can get the exact number of days between two dates?
An example of business days calculation in SQL */
/* The algorythm is: */
/* 1) Take the absolute difference between the dates */
/* to_date('&todate') - to_date('&frdate') */
/* 2) Subtract the weekends (number of weeks in the range */
/* TRUNC(to_date('&todate'),'D') = 1st day of week that */
/* end of period is in */
/* TRUNC(to_date('&frdate'),'D') = Last day of week that */
/* start of period is in */
/* So subtracting these two gives the number of days */
/* between the two dates but including all of the days in */
/* the weeks that the dates start and end in. When this */
/* number is divided by 7 it gives the number of weeks. */
/* Multiplying by 2 gives the number of weekend days. */
/* 3) Subtract 1 day if the ending date is on a saturday */
/* DECODE(to_char(to_date('&todate'),'D'),7,-1,0) */
/* --> If the day of the week is saturday (7), returns -1 */
/* 4) Subtract 1 day if the start date is on a sunday */
/* DECODE(to_char(to_date('&frdate'),'D'),1,-1) */
/* --> If the day of the week is sunday (1), returns 1 */
/* 5) Add one day to make the range inclusive (The '1 + ' ) */
/* Author: Kenneth Atkins ([email protected]) */
/* http://www.olywa.net/katkins/oratip */
define frdate = '&1'
define todate = '&2'
set verify off
select
'&frdate' From_Date
,'&todate' To_Date,
1 + to_date('&todate') - to_date('&frdate') -
((TRUNC(to_date('&todate'),'D') - TRUNC(to_date('&frdate'),'D'))/7)*2
+ DECODE(to_char(to_date('&todate'),'D'),7,-1,0)
+ DECODE(to_char(to_date('&frdate'),'D'),1,-1,0) Business_Days
from dual
Here is an example of running the script:
SQL> @busdays 01-AUG-96 15-AUG-96
FROM_DATE TO_DATE BUSINESS_DAYS
01-AUG-96 15-AUG-96 11 -
How do i get number of days between 2 dates?
How do i get number of days between 2 dates?
and the result must be in int.
for example
Ex. startdate: 2006-06-01 enddate: 2006-06-30 and the result is: 30
how to do so? thxmel
Iv'e used this method. It assumes startdate,enddate and days have been defined before but you could pass them as args.
void days()
try
Date d1 = DateFormat.getDateInstance().parse(startdate);
Date d2 = DateFormat.getDateInstance().parse(enddate);
long days = (d2.getTime()-d1.getTime())/1000/60/60/24;
days = ""+days;
catch (ParseException e)
System.out.println("Invalid date format");
}It actually gets the duration in ms and divides down to days.
Regards
Chris -
How to get total number of days in current Fiscal period/year
Hi,
I need to get total number of days in current Fiscal period/year (current month) and assign it to an infoobject. I need a routine for this. Is there any function module to get this.If possible pls paste the ABAP code also for this task. Thanks in advancehere is the FM:
LAST_DAY_IN_PERIOD_GET
KJ!!! -
Getting number of days between 2 dates
Hello All,
I require the number of days between 2 dates.
The number of days is between low date : PR Date (not an input variable) and the high date.
I have created an customer exit variable to get sy-datum in made it as formula variable.
I have also created a formula variable for PR Date , and subtracted the 2 dates.
It is not giving the correct result.
Any suggestions.
Thanks & Regards,
VLRead through this web link. It will show you how to calculate the days between 2 dates directly in your BEX query.
No exit needed to calculate this.
http://teklink.co.uk/sap/sap-bi-bw-how-to-use-replacement-path-variables-to-perform-date-calculations-in-the-bex-analyzer/ -
How can I get number of days between 2 dates ?
How can I get number of days between 2 dates ?
Give me answer as soon as possible.....Mukesh_Prajapat wrote:
How can I get number of days between 2 dates ?
Give me answer as soon as possible.....Is google broken again?
[How To Ask Questions The Smart Way|http://www.catb.org/~esr/faqs/smart-questions.html] -
How can i get number of days between two dates represented by two dates?
how can i get number of days between two dates represented by two date objects. One is java.sql.Date, the other is java.util.Date?
tej_222 wrote:
But how do I do that conversion. from java.sql.date and java.util.date to calender?
-thanks for the quick response.You may find the following utility code samples useful:
[http://balusc.blogspot.com/2007/09/calendarutil.html]
[http://balusc.blogspot.com/2007/09/dateutil.html]
ganeshmb wrote:
(date1.getTime() - date2.getTime())/(1000*60*60*24) should do.
getTime returns millsecond value of date object and the difference divided by no of milliseconds in a day should fetch you the difference in terms of days.This doesn't respect the DST. Use java.util.Calendar. -
Adobe LiveCycle Designer 8 - Add days to Current Date in another text field
Hi-
I am working on an expense report. I have six fields, CurrentDate, and countDate1 through countDate5. The CurrentDate is a Time/Date field which the user can select whatever date is needed with the drop down calendar. The other five countDate fields are "text" fields which will represent Monday through Friday. I would like to add zero days to whatever the user selects as the CurrentDate and make that appear in countDate1 which represents Monday(the CurrentDate the user selects will always be a Monday), add one day to whatever the user selects as the CurrentDate and make that appear in countDate2 which represents Tuesday...and so on. I realize this is probably basic for someone familiar with FormCalc but I'm very new at this.
This got me very close but I want the user to select the date and not have the CurrentDate already filled in.
CurrentDate - DateTime field, FormCalc calculation script:
num2date(Date())
Date1 - Text field, FormCalc calculation script:
Num2Date( Date2Num(CurrentDate.formattedValue))
Date2 - Text field, FormCalc calculation script:
Num2Date( Date2Num(CurrentDate.formattedValue) + 1 )
Thanks!
BrianHere is an exmaple of adding days the script is used in the "exit" event for the date select field that has display format of "MM/DD/YYYY". Adding days requires add x number of days to the days since the epoch date for the current date, adding months or years one needs to manipulate the string parts of the date.
----- form1.#subform[0].InputDateField::exit: - (FormCalc, client) ---------------------------------
// fomatted string for selected date
var sFmtDateValue = $.formattedValue
var sMsg = Concat("Entered date formatted: ", sFmtDateValue) // build message string
sMsg = Concat(sMsg, "\u000a" ) // add new line to message
// convert date string to days since epoch date - format is important
var fDaysPast = Date2Num(sFmtDateValue, "MM/DD/YYYY")
// add 7 days to days past epoch date
var f7DaysPlus = fDaysPast + 7 // add 7 days
var s7DaysPlus = Num2Date(f7DaysPlus, "MMM DD, YYYY") // format string for 7 days plus
sMsg = Concat(sMsg, "\u000a", "Plus 7 Days: ", s7DaysPlus) // build message string
// add 14 days to days past epoch date
var f14DaysPlus = fDaysPast + 14 // add 7 days
var s14DaysPlus = Num2Date(f14DaysPlus, "MMMM DD, YYYY") // format string for 7 days plus
sMsg = Concat(sMsg, "\u000a", "Plus 14 Days: ", s14DaysPlus) // build message string
// display results
// work on months
// get parts of date past epoch date
var sFullYear = Num2Date(fDaysPast, "YYYY") // get 4 digit year form days past epoch date
var sMonth = Num2Date(fDaysPast, "MM") // get month form days past epoch date as number
var sDate = Num2Date(fDaysPast, "DD") // get date form days past epoch date as a number
var s2Month = Sum(sMonth, 2) // add 2 months
var s2FullYear = sFullYear
// if more than 12 months in new date adjust year on number of months
if (s2Month > "12") then
s2FullYear = Sum(s2FullYear, + 1) // increment year
s2Month = Sum(s2Month, - 12) // adjsut months
endif
var s2MonthsAdded = Concat(s2Month, "/", sDate, "/", s2FullYear) // date string
sMsg = Concat(sMsg, "\u000a", "Added 2 months: ", s2MonthsAdded) // display stringxfa.host.messageBox(sMsg, "Sample Adding Days" ,3, 0);
var s5Month = Sum(sMonth, 5) // add 5 months
var s5FullYear = sFullYear
// if more than 12 months in new date adjust year on number of months
if (s5Month > "12") then
s5FullYear = Sum(s5FullYear, + 1) // increment year
s5Month = Sum(s5Month, - 12) // adjsut months
endif
var s5MonthsAdded = Concat(s5Month, "/", sDate, "/", s5FullYear) //build Date string
sMsg = Concat(sMsg, "\u000a", "Added 5 months: ", s5MonthsAdded) // display stringxfa.host.messageBox(sMsg, "Sample Adding Days" ,3, 0);
// display results
xfa.host.messageBox(sMsg, "Sample Adding Days and Months" ,3, 0); -
Can I create a field that calculates number of days from a date field?
Hi all,
I need a field that will calculate the number of days elapsed whatever date is entered into the date field, and update that number of days based on the calendar/computer calendar date. Does that make sense?
https://www.dropbox.com/s/arkmnsxjkl4r156/AFBS_FacilitySpecialCareList02.pdf
I set up the form so that my boss can add or subtract clients from the list. Each client needs to have its own "Days since added to the list" number. Sorta like a little aging report.
Is this possible?
Many thanks,
LauraWow, I'm so stumped. I tried to copy a bit of formcalc into the exit event for my current date field to try to make this happen, but I can't get it to work.
My attempt at scripting is embarrassing, but here it is:
form1.sf1.CCSub.CCGroup.#subform[0].DateField2::exit - (FormCalc, client)
form1.sf1.CCSub.CCGroup.#subform[0].NumericField2.rawValue = Date2Num(DateField1, "MM-DD-YY") - Date2Num(DateField2, "MM-DD-YY")
and here's the file:
https://www.dropbox.com/s/arkmnsxjkl4r156/AFBS_FacilitySpecialCareList02.pdf
Can anyone help me get this right?
Sign me: One Lost Designer
Thanks! -
How to calculate number of days between two date in Template design?
Hello guys
I have a situation where I have to create a template that returns data, and one of the thing of the existing report is that there is a column that is actually the number of days between start date and end date columns..
So in template, how would I be able to do the same? I have start date and end date columns on the template, now when I created another column using expression like end date - start date and preview the template, I am getting errors saying :
Caused by: oracle.xdo.parser.v2.XPathException: Cannot convert 03/31/2009 to number.
at oracle.xdo.parser.v2.XSLStylesheet.flushErrors(XSLStylesheet.java:1534)
at oracle.xdo.parser.v2.XSLStylesheet.execute(XSLStylesheet.java:521)
at oracle.xdo.parser.v2.XSLStylesheet.execute(XSLStylesheet.java:489)
at oracle.xdo.parser.v2.XSLProcessor.processXSL(XSLProcessor.java:271)
at oracle.xdo.parser.v2.XSLProcessor.processXSL(XSLProcessor.java:155)
at oracle.xdo.parser.v2.XSLProcessor.processXSL(XSLProcessor.java:192)
Please advice
ThanksHi
There is an extension function you can use, from the javadoc:
date_diff
public static long date_diff(java.lang.String format,
java.lang.String fromDate,
java.lang.String toDate,
java.lang.String locStr,
java.lang.String tzID)
Method to get the difference between two dates in the given locale. The dates need to be in "yyyy-MM-dd" format. This function supports only Gregorian calendar.
Parameters:
format - the format to which the difference is required; allowed formats are y (for Year), m(for month), w(for week), d(for day), h(for hour), mi(for minute), s(for seconds) and ms(for milliseconds)
fromDate - the first date
toDate - the second date
locStr - locale string -> lang-Territory
tzID - timezone ID ->http://java.sun.com/j2se/1.4.2/docs/api/java/util/TimeZone.html
Returns:
the difference in dates in the desired format
For example
<?xdoxslt:date_diff(‘d’,’2009-09-14’, ‘2009-09-20’,’en-US’,1)?>
give a result of 6
You can substitute in columns for the dates, just remember the date format required.
Regards
Tim -
I wanted to know how do you calculate the number of days between two dates
i wanted to know how do you calculate the number of days between two dates in java ? i get both the dates from the database. i guess there are many issues like leap year and Febuary having diff no of months ..etc.
thanks..
I solve my problem as
public class MyExample {
public static void main(String a[]) {
String stdate = "2009-03-01";
java.sql.Date currentDate = new java.sql.Date(System.currentTimeMillis());
java.sql.Date preDate = java.sql.Date.valueOf(stdate);
System.out.println(currentDate);
System.out.println(preDate);
// int dateCom = preDate.compareTo(currentDate);
// System.out.println(dateCom);
long diff = currentDate.getTime() - preDate.getTime();
int days = (int) Math.floor(diff / (24 * 60 * 60 * 1000));
System.out.println(days);
} -
How to calculate number of days from a date field
Dear BW Experts.
I have a field 'Create Date' in the BEx query. Now we need to create a variable which should give the number of days from the date of running the query (sy-datum) to the Create Date.
This will help the users to get records which are say, 30 days old (Sy-datum - create date = 30) or 10 days old etc.
Could you suggest as to how to create this variable.
Thanks,
SaiHi,
Step 1: Create variable on "Create Date" with User entry processing type
Step 2: Create a restricted KF for Sales & restrict it on "Create Date" to get "Sales on day"
Step 3: Manipulate the values of "Create Date" on which you could restrict "Sales" again and again to get other values
Step 4: Create one variable (ZPUTMNTH) for u201CMonth to Dateu201D with processing by u201CCustomer Exitu201D. This variable was created on u201CDateu201D characteristics.
Step 5 : Goto C-mod t-code and use EXIT_SAPLRRS0_001
to calculate "month to date" user input is "Calday" Key Date
WHEN 'ZPUTMNTH'.
IF I_STEP = 2. "after the popup
LOOP AT I_T_VAR_RANGE INTO LOC_VAR_RANGE
WHERE VNAM = 'ZPDATE'.
CLEAR L_S_RANGE.
L_S_RANGE-LOW = LOC_VAR_RANGE-LOW(6). "low value, e.g.YYYYMM (200606) part of key date (20060625)
L_S_RANGE-LOW+6(2) = '01'. u201C low value e..g. YYYYMM01 (20060601)
L_S_RANGE-HIGH = LOC_VAR_RANGE-LOW. "high value = input
L_S_RANGE-SIGN = 'I'.
L_S_RANGE-OPT = 'BT'.
APPEND L_S_RANGE TO E_T_RANGE.
EXIT.
ENDLOOP.
ENDIF.
Assign if helps.....
Regards,
Suman -
I would like to format cells with time only. when I enter a time of day the current date is still in the cell which is not necessarily so. THere are no options for just date .
christine275 wrote:
... (this is a time worked by date and not always entered on the date worked)--
"Time" in Numbers is always "Time of Day", and is always part of a Date and Time value. "Amount of Time" is a Duration value, which may be displayed in a similar format to "Time of Day," but is a different type of value.
If you are entering the number of hours and minutes worked, format the column as Duration, set the units and the format in which you want to have the value appear.
The Date column will still contain a Date and Time value (Jan 1, 2011 00:00:00 in the cell shown in the example), but the "Time Worked" cells will contain only a Duration value.
Incidently, the Date in A2 was entered as "jan 1" (without the quotes). Numbers automatically adds the current year and the default time value, then displays the result in the closest format to what you've entered, or in the Date and Time format you have chosen.
The Duration value in B2 was entered as 3:15 (as displayed). Note that in the entry bar the duration is displayed as 3h 15m, probably to distinguish it from a similarly formatted (Date and) Time value.
Regards,
Barry -
Number of days in given date/month
Hi,
Can you send query to find the number of days in given date/month
Regards,
Venkat.If you want No. of days between two date then you can just Subtract them. If you want the number of days in a month you can get the first and last day of the month and subtract them.
Solution for a month.
SQL> with t as (select to_date('&month','mmyyyy') as dt from dual)
2 select (last_day(dt) - trunc(dt, 'mm'))+1
3 from t
4 /
Enter value for month: 012009
old 1: with t as (select to_date('&month','mmyyyy') as dt from dual)
new 1: with t as (select to_date('012009','mmyyyy') as dt from dual)
(LAST_DAY(DT)-TRUNC(DT,'MM'))+1
31
SQL> /
Enter value for month: 022009
old 1: with t as (select to_date('&month','mmyyyy') as dt from dual)
new 1: with t as (select to_date('022009','mmyyyy') as dt from dual)
(LAST_DAY(DT)-TRUNC(DT,'MM'))+1
28
SQL> /
Enter value for month: 122009
old 1: with t as (select to_date('&month','mmyyyy') as dt from dual)
new 1: with t as (select to_date('122009','mmyyyy') as dt from dual)
(LAST_DAY(DT)-TRUNC(DT,'MM'))+1
31Edited by: Karthick_Arp on Feb 19, 2009 9:56 PM
Maybe you are looking for
-
Hi All, How Loading / Captilization of different expenses like freight, entry tax, installation charges, customs duty & C&F Charges will be handled in SAP??? regards
-
Export a Forms Library Item to Word or Excel for editing
We are using MOSS 2007 and using InfoPath 2010 I created a Forms library to enter new items in a web-based form. The requirement is to be able to open a list item and save it to an editable Word or Excel file - without using programming, if possible.
-
My Prefs' in Photoshop are sRGB since I work for web only. My CS3 color settings are synchronised in Bridge, Europe General Purpose. Fireworks exports always in sRGB. When I want to safe an image for web (Photoshop) the colour that I see in the Safe
-
Please advise
-
Is there any way I can convert previous apple accounts into my most recent one? As I have forgotten the older accounts passwords.