Find month and year of a given date
Hi,
How to find the month and year of a given date.
month ( sy-datum) year ( sy-datum )
--Bala
hi
DATA: EDAYS LIKE VTBBEWE-ATAGE,
EMONTHS LIKE VTBBEWE-ATAGE,
EYEARS LIKE VTBBEWE-ATAGE.
PARAMETERS: FROMDATE LIKE VTBBEWE-DBERVON,
TODATE LIKE VTBBEWE-DBERBIS DEFAULT SY-DATUM.
Call Function 'FIMA_DAYS_AND_MONTHS_AND_YEARS'
exporting
i_date_from = FROMDATE
i_date_to = TODATE
I_FLG_SEPARATE = ' '
IMPORTING
E_DAYS = EDAYS
E_MONTHS = EMONTHS
E_YEARS = EYEARS.
WRITE:/ 'Difference in Days ', EDAYS.
WRITE:/ 'Difference in Months ', EMONTHS.
WRITE:/ 'Difference in Years ', EYEARS.
INITIALIZATION.
FROMDATE = SY-DATUM - 60.
Using teh abiove u can get difference but when u pass previous year u wont get the exact.
There is no seperate FM for this, u have to use three FM.
If possible using these three FM code u can create an FM.
For years and months between two days:
DATA: EYEARS LIKE VTBBEWE-ATAGE.
PARAMETERS: FROMDATE LIKE PREL-BEGDA,
TODATE LIKE PREL-BEGDA DEFAULT SY-DATUM.
CALL FUNCTION 'COMPUTE_YEARS_BETWEEN_DATES'
EXPORTING
first_date = fromdate
MODIFY_INTERVAL = ' '
second_date = todate
IMPORTING
YEARS_BETWEEN_DATES = EYEARS
EXCEPTIONS
SEQUENCE_OF_DATES_NOT_VALID = 1
OTHERS = 2
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
Write:/ eyears.
DATA: EMONTHS LIKE VTBBEWE-ATAGE.
PARAMETERS: FROMDATE LIKE SY-DATUM,
TODATE LIKE SY-DATUM
DEFAULT SY-DATUM.
CALL FUNCTION 'MONTHS_BETWEEN_TWO_DATES'
EXPORTING
i_datum_bis = fromdate
i_datum_von = todate
I_KZ_INCL_BIS = ' '
IMPORTING
E_MONATE = emonths
write:/ emonths
CALL FUNCTION 'DAYS_BETWEEN_TWO_DATES'
EXPORTING
I_DATUM_BIS = x_faede-zfbdt
I_DATUM_VON = p_fdat
I_KZ_EXCL_VON = '0'
I_KZ_INCL_BIS = '0'
I_KZ_ULT_BIS = ' '
I_KZ_ULT_VON = ' '
I_STGMETH = '0'
I_SZBMETH = '1'
IMPORTING
E_TAGE = dias_v.
IF SY-SUBRC <> 0.
ENDIF.
x_faede-zfbdt -> 20050915
p_fdat -> 20050811
dias_v = 4
try this and let me know.
regards
ravish
<b>plz dont forget to reward useful points</b>
Similar Messages
-
How to get Week,Month and Year details from a date column
Hi frenz,
I've a column like tran_date which is a date column..... I need the next week details based on this column and so on...
I need month and year details as well based on this tran_date column.... can any one tell me how...
Thanks in advanceMy example for objects:
create or replace type date_object as object
centure number,
year number,
month number,
day number,
hour number,
minute number,
second number,
daypart number,
week number,
constructor function date_object(p_dt date)
return SELF as result
create or replace type body date_object is
constructor function date_object(p_dt date)
return SELF as result
as
begin
SELF.centure:= trunc(to_char(p_dt,'YYYY')/100);
SELF.year:= to_char(p_dt,'YYYY');
SELF.month:= to_char(p_dt,'MM');
SELF.day:= to_char(p_dt,'DD');
SELF.hour:= to_char(p_dt,'HH24');
SELF.minute:= to_char(p_dt,'MI');
SELF.second:= to_char(p_dt,'SS');
SELF.daypart:= p_dt-trunc(p_dt,'DD');
SELF.week:= to_char(p_dt,'IW');
return;
end;
end;
select date_object(sysdate),
date_object(sysdate).year
from dual;Regards,
Sayan M. -
Problem to insert only month and year instead of full date
select b.penjara_id, p.penj_lokasi, a.no_daftar, b.episod, b.nama1,to_char(a.trkh_mula_prl,'dd/mm/yyyy') as trkh_mula_prl, to_char(bulan_proses,'mm/yyyy') as bulan_proses,
b.epd, b.lpd
from prl_daftar_proses a, senarai_pesalah b, penjara p
where a.no_daftar=b.no_daftar
and a.episod=b.episod
and b.penjara_id = p.penjara_id
and a.setuju_jplp is null
and a.bulan_proses between to_date(:FROM,'dd/mm/yyyy') and to_date(:TO,'dd/mm/yyyy')
order by b.penjara_id, a.bulan_proses,a.no_daftarHi,anyone can help me how i can insert only month and year from the value that have full date in the database??
for example,the date is 09/18/2012, but i just want to insert 09/2012 as parameter. If i want to insert only one parameter, i can do that..But i have problem when I want to insert two parameters..jeneesh wrote:
Welcome to the forum..
This..?
Assuming bulan_proses is a date without time part
select b.penjara_id, p.penj_lokasi, a.no_daftar, b.episod, b.nama1,to_char(a.trkh_mula_prl,'dd/mm/yyyy') as trkh_mula_prl, to_char(bulan_proses,'mm/yyyy') as bulan_proses,
b.epd, b.lpd
from prl_daftar_proses a, senarai_pesalah b, penjara p
where a.no_daftar=b.no_daftar
and a.episod=b.episod
and b.penjara_id = p.penjara_id
and a.setuju_jplp is null
and a.bulan_proses between to_date(:FROM,'mm/yyyy') and last_day(to_date(:TO,'mm/yyyy'))
order by b.penjara_id, a.bulan_proses,a.no_daftar
i got another problem..
before that.may i know what is the function of last_day? -
How to get the currrent month and year from a new date object
If I create a new Date object as "d",
java.util.Date d = new java.util.Date();how can I format the date to get the current Month as 'Jan' and the current year as '2008'. So if I have something like d.getMonth() gets the current month as 'Oct' and d.getYear() gets '2008'
Thanks,
Zub[Read the flamin' manual you must. Hmm.|http://en.wikipedia.org/wiki/RTFM]
~~ Yoda.
Well no actually, he didn't say that, but he should have.
Cheers. Keith.
PS: Don't say that to a 7 foot pissedOff wookie when he's got his head stuck in a smoking hyperdrive, and you're being chased by a S-class battle cruiser... Ask Yoda how he got to be so short.
PPS: It is the SimpleDateFormat you seek ;-)
Edited by: corlettk on 14/10/2008 22:37 ~~ Also far to slow... but funny. -
Find the difference between two dates for the specific month and year
Hi,
I have two dates, start date is 30/12/2012 and end date is 04/01/2013. Using datediff I found the difference of days between two dates. But I find the no of days in January 2013. ie output is 4 instead of 6. I input month and year to find the no of days
for that date. In this case I input Jan 2013. How can I sql this ?I don't understand how most of the answers provided here not analytically solving the problem with many cases possible.
First let me understand you:
You have 2 dates range and you want to calculate day range for specific month and year between the original date range.
declare @for_month int = 1 --January
declare @for_year int = 2013
declare @StartDate date = '2012-12-20'
declare @EndDate date = '2013-01-04'
SELECT
CASE
WHEN (DATEPART(MONTH, @StartDate) = @for_month and DATEPART(MONTH, @EndDate) = @for_month) and ((DATEPART(YEAR, @StartDate) = @for_year or DATEPART(YEAR, @EndDate) = @for_year)) THEN
DATEDIFF(DAY, @StartDate,@EndDate)
WHEN (@StartDate < cast(CONVERT(varchar(4), @for_year) + '-' + CONVERT(varchar(2), @for_month) + '-01' as date)) and (@EndDate between (cast(CONVERT(varchar(4), @for_year) + '-' + CONVERT(varchar(2), @for_month) + '-01' as date)) and (cast(DATEADD(d, -1, DATEADD(m, DATEDIFF(m, 0, cast( CONVERT(varchar(4), @for_year) + '-' + CONVERT(varchar(2), @for_month) + '-01' as date)) + 1, 0)) as date))) THEN
DATEDIFF(DAY, DATEADD(MONTH, DATEDIFF(MONTH, -1, @EndDate)-1, 0),@EndDate)
WHEN (@EndDate > cast(DATEADD(d, -1, DATEADD(m, DATEDIFF(m, 0, cast( CONVERT(varchar(4), @for_year) + '-' + CONVERT(varchar(2), @for_month) + '-01' as date)) + 1, 0)) as date)) and (@StartDate between (cast(CONVERT(varchar(4), @for_year) + '-' + CONVERT(varchar(2), @for_month) + '-01' as date)) and (cast(DATEADD(d, -1, DATEADD(m, DATEDIFF(m, 0, cast( CONVERT(varchar(4), @for_year) + '-' + CONVERT(varchar(2), @for_month) + '-01' as date)) + 1, 0)) as date))) THEN
DATEDIFF(DAY, @StartDate,DATEADD(d, -1, DATEADD(m, DATEDIFF(m, 0, @StartDate) + 1, 0))) + 1
WHEN ((DATEDIFF(DAY, @StartDate, cast(DATEADD(d, -1, DATEADD(m, DATEDIFF(m, 0, cast( CONVERT(varchar(4), @for_year) + '-' + CONVERT(varchar(2), @for_month) + '-01' as date)) + 1, 0)) as date)) >= 0) and (DATEDIFF(DAY, cast(CONVERT(varchar(4), @for_year) + '-' + CONVERT(varchar(2), @for_month) + '-01' as date), @EndDate) >= 0)) THEN
DATEDIFF(DAY, cast( CONVERT(varchar(4), @for_year) + '-' + CONVERT(varchar(2), @for_month) + '-01' as datetime), DATEADD(d, -1, DATEADD(m, DATEDIFF(m, 0, cast( CONVERT(varchar(4), @for_year) + '-' + CONVERT(varchar(2), @for_month) + '-01' as datetime)) + 1, 0))) + 1
ELSE
0
END as [DD]
I don't know how you calculate day range between 01/01/2013 and 04/01/2013
is 4, it is actually is 3 but if that is the case, you can add 1 from the condition. -
To get first date and end date after entering any month and year
Hi,
I need to to get first date and end date of a month and year in yyyyMMdd format. I am reading month and year from a properties file. But I don't know how to get the first date and End date in given format. The properties file gives me just text. But I don't know how to get the date format using this. I need this urgently. Can anyone help me to get code for this?
I am reading the fields as,
Properties props = new Properties();
props.load(new FileInputStream("AnyMonthVolume.properties"));
String date_month = props.getProperty("date_month");
String date_year = props.getProperty("date_year");
Thanks.I know this has been posted a while ago but incase someone looking for it, here is the code to get the end of current month date.
Calendar cal = Calendar.getInstance();
cal.setTime(new java.util.Date());
cal.set(Calendar.DATE, 1); //set the date to start of month
cal.add(Calendar.MONTH,1);
cal.add(Calendar.DATE,-1);
System.out.println(cal.getTime()); -
When my delegates are filling in a event form i have put together, a large number of them forget to change either the month or year on the date field. Is there a way to have a date field that has drop down boxes for day, month and year so they have to choose rather than a date been already on the screen??
ThanksHi Christopher,
The WEEKDAY function allows specifying either Sunday or Monday as the first day of the week:
WEEKDAY
The WEEKDAY function returns a number that is the day of the week for a given date. WEEKDAY(date, first-day)
 date: The date the function should use. date is a date/time value. The time portion is ignored by this function.
 first-day: An optional value that specifies how days are numbered.
Sunday is 1 (1 or omitted): Sunday is the first day (day 1) of the week and Saturday is day 7.
Monday is 1 (2): Monday is the first day (day 1) of the week and Sunday is day 7. Monday is 0 (3): Monday is the first day (day 0) of the week and Sunday is day 6.
But I think you are referring to the first day of the 'workweek', for which I do not see a means of defining a custom value.
Since you want to 'insert categories', though, you could easily define your own, using WEEKDAY(date) or WEEKDAY(date,1), plus an IF statement to return the category label appropriate to the day. Here's one for a Sunday to Thursday work week. Dates are in column A, the formula is in whichever column you want as the Category column. For the example, I've placed it in column B.
B2, and filled down: =IF(WEEKDAY(A)<6,"Work","Off")
The top table shows the weekday numbers returned for each day of the week for each of the three permitted values for the optional second argument. The bottom table shows the results from the formula above, used to define a category label for each date:
A10 was left blank intentionally, to determine if the lack of data resulted in an error. The Warning message, flagged by the blue 'warning' triangle, is "The formula uses a number in place of a date." The 'date' assigned to this numerical value of zero was a Friday, but I'm not certain when. Probably best to avoid extra rows with no date shown.
Regards,
Barry -
Data element for Month and Year
Hello All,
Is there any data element which will have only Month and Year.
I have to introduce this field in a table. It should have convesion exits also.
Ex: If i give 092009, it sould come like 09.2009
Thank you.
Best Regards,
Sasidhar Reddy Matli.Kindly Try this code for Month and year as input and having standard F4 help..
INCLUDE RMCS0F0M.
TYPES : BEGIN OF TY_SELECT,
MONTH TYPE FTI_MONTH_YEAR,
END OF TY_SELECT.
DATA : WA_SELECT TYPE TY_SELECT.
SELECTION-SCREEN : BEGIN OF BLOCK SANDEEP WITH FRAME.
SELECT-OPTIONS : S_MONTH FOR WA_SELECT-MONTH OBLIGATORY NO INTERVALS NO-EXTENSION.
SELECTION-SCREEN : END OF BLOCK SANDEEP.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR S_MONTH-LOW.
PERFORM MONAT_F4.
SANDEEP JAIN -
TO GET WEEKS for a given MONTH AND YEAR
Is there any FM to get the no of weeks for a given month, say 01 2005.
Can i get the week numbers say 1 2 3 4 5 for the given month and year.
Please let me know.
Happy Holidays.
Regards,
Manohar EHi Manohar,
Use FM DATE_GET_WEEK twice; first time pass first day of the month and again pass the last day of the month as a parameter. So u will be having week number(yyyyxx) for the first week of the month and week number for the last week of the month. From these two, in between week numbers u can easily fetch. I hope this will help u out.
Regards,
Kavya Shah -
Could some body help me:
I am try to get Date, Month and Year
I got stuck, Anyone help me this:
public class DateMonth
public static void main(String[] args)
toDay = new toDay("February 21, 2002");
dayofWeek = today.getDay();
System.out.println("Current month is " + toDay.getMonth());
System.out.println("Current day is " + getDate());
System.out.println("Current year is " + toDay.getYear());
toDay.setDate(toDay.getDate()+60)
System.out.println("Sixty days from now is ");
System.out.println(toDay);
}Try something like this:
import java.util.*;
public class DateMonth {
public static void main(String[] args) {
// Note: 0 = January
Calendar calendar = new GregorianCalendar();
System.out.println("YEAR: " + calendar.get(Calendar.YEAR));
System.out.println("MONTH: " + calendar.get(Calendar.MONTH));
System.out.println("WEEK_OF_YEAR: " + calendar.get(Calendar.WEEK_OF_YEAR));
System.out.println("WEEK_OF_MONTH: " + calendar.get(Calendar.WEEK_OF_MONTH));
System.out.println("DATE: " + calendar.get(Calendar.DATE));
System.out.println("DAY_OF_MONTH: " + calendar.get(Calendar.DAY_OF_MONTH));
System.out.println("DAY_OF_YEAR: " + calendar.get(Calendar.DAY_OF_YEAR));
System.out.println("DAY_OF_WEEK: " + calendar.get(Calendar.DAY_OF_WEEK));
// 60 days from now
calendar.add(calendar.DATE, 60);
System.out.println("\nSixty days from now");
System.out.println("MONTH: " + calendar.get(Calendar.MONTH));
System.out.println("DATE: " + calendar.get(Calendar.DATE));
System.out.println("YEAR: " + calendar.get(Calendar.YEAR));
}Remember that January is 0!
Take a look at the GregorianCalendar class:
http://java.sun.com/j2se/1.3/docs/api/java/util/GregorianCalendar.html
Hope this helps!
DesQuite -
Date must be truncated to month and year
Hi,
I have a date field
after the user gives F4 help I need to truncate the date , i.e I want only month and year
For Ex.
If the user selects as 12/12/2009
I must display as 12/2009
How can It be done?Hi,
go thru this threads
Re: Date validation and conversion
Re: Is DD/MM/YYYY supported in webdynpro for abap application
it might provide you some guidance -
Date Picker: Only select Month and Year
Hallo,
I try to configure the Date Picker. For the users it should only be possible to select Month and Year. The column should be automaticly completed with the first day of the select month and a static time (00:00:00).
How can I do this?
SincerlyYou can't do that with a standard date picker. What you could do is to use it and after you change the value in it you modify the value using javascript and ajax similar to what I do in this example:
http://htmldb.oracle.com/pls/otn/f?p=31517:9
Denes Kubicek
http://deneskubicek.blogspot.com/
http://www.opal-consulting.de/training
http://apex.oracle.com/pls/otn/f?p=31517:1
------------------------------------------------------------------- -
Date concatenation using MONTH and YEAR
Env : Oracle Reports 9I.
I need to display reports based on dates.
If the user enters in one field 'SEP' and in another '2005',
how can I concatenate both the fields as one and then display
all results for SEP 2005?
The Table has a field called Eff_Date (of type Date)
and containing values:
Eff_Date
==============
01-09-05
02-09-05
04-09-05
05-09-05
My code is
SELECT col1,
col2
FROM TableA
Where TRUNC(Eff_Date )=:MONTH ?? PARAMETER: Here is the month : SEPT
and TRUNC(Eff_date) =:YEAR ?? PARAMETER: Here is the Year : 2005I need to concatenate parameters MONTH and YEAR in one and then
display records for that month.
How can I write the SQL Query to concatenate MONTH and YEAR and
TRUNCATE the column eff_date?
Please help.Env : ORACLE REPORTS 9I
I am passing 3 parameters to the report:
Parameters are of type CHAR
Report Parameters
Year / Month : 2005 / AUG
Effective Date :
The colunm in table is eff_date
eff_date
01/08/2005
02/08/2005
03/08/2005
15/09/2005
17/09/2005
18/09/2005
29/09/2005The problem is:
1)If I dont enter anything,I just get displayed 2 record for the above.
It should display all records rather than 2.
2)If I enter Effective date as 01-AUG-2005,no records are displayed.
This is my code:
Select col1,col2
from TableA
where ( TRUNC(ch.eff_date) = nvl (:E_DATE, TRUNC(ch.eff_date) )
AND TRUNC(ch.eff_date, 'MONTH') = nvl (TO_DATE(:YR||:MTH, 'yyyymon') ,
TRUNC(ch.eff_date) )
)Shud i change the AND to OR? -
Getting Day, month and year from Date object
hello everybody,
Date mydate = Resultset.getDate(indexField);
Now i would like to get day, month and year from mydate.
In another words, i'm looking for something equivalent to
mydate.getDay() as this method is deprecated.
Can somebody help me out please?
Thank you in advance,swvc2000,
Here is a sample class that demonstrates two ways in which to do this.import java.util.*;
import java.text.*;
public class DateSplitter {
public static void main(String args[]) {
/* even though your date is from a result set,
pretend the following date is your date that
you are using. The try catch block is used
because I hand-crafted my date using
SimpleDateFormat. Substitute your date.*/
Date yourDate = null;
try {
SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy");
yourDate = formatter.parse("05/06/2000");
} catch (ParseException e) { }
//the following gets the current date
Calendar c = Calendar.getInstance();
//use the calendar object to set it to your date
c.setTime(yourDate);
//note months start at zero
int month = c.get(Calendar.MONTH);
int year = c.get(Calendar.YEAR);
int dayOfMonth = c.get(Calendar.DAY_OF_MONTH);
System.out.println("Calendar Month: "+month);
System.out.println("Calendar Day: "+dayOfMonth);
System.out.println("Calendar Year: "+year);
System.out.println();
/* Simple date format can also be used to strip them
out of your date object. When you use it, notice that
months start at 1. Also, it returns string values. If
you need integer values, you will have to use
Integer.parseInt() as I did below. If you are
only concerned about the string values, just remove
the Integer.parseInt part. */
DateFormat formatter = new SimpleDateFormat("M");
month = Integer.parseInt(formatter.format(yourDate));
System.out.println("SDF Month: "+ month);
formatter = new SimpleDateFormat("d");
dayOfMonth = Integer.parseInt(formatter.format(yourDate));
System.out.println("SDF Day: "+ dayOfMonth);
formatter = new SimpleDateFormat("yyyy");
year = Integer.parseInt(formatter.format(yourDate));
System.out.println("SDF Year: "+ year);
}//end main
}//end DateSplitter classtajenkins -
Loop through month and year till date while using a merge statement
Hello Guys,
I have 2 tables with the following datas in them:-
Company
CompanyId CompanyName
1 Company1
2 Company2
3 Company3
Employees
EmployeeId EmployeeName CompanyId StartDate
1 Employee1 1 12/21/2011
2 Employee2 1 01/20/2012
3 Employee3 2 03/23/2012
4 Employee4 2 07/15/2012
5 Employee5 2 01/20/2013
6 Employee6 3 12/17/2013
Now i want to check, How many people were recruited in the team in the specified month and year? I have the storage table as follows:-
RecruiterIndicator
CompanyId Year Month EmployeeRecruited
1 2011 12 1
1 2012 1 1
2 2012 3 1
2 2012 7 1
2 2013 1 1
3 2013 12 1
This should be a merge stored procedure that should update the data if it is present for the same month year and company and insert if that is not present?
Please help me with this
Thanks
AbhishekIt's not really clear where the merge to come into play. To get the RecruiterIndicator table from Employess, this query should do:
SELECT CompanyId, Year(StartDate), Month(StartDate), COUNT(*)
FROM Employees
GROUP BY CompanyId, Year(StartDate), Month(StartDate)
Erland Sommarskog, SQL Server MVP, [email protected]
Maybe you are looking for
-
Problem with facebook in Nokia C6-00.
There was a default Facebook application in my phone when I bought it but it got deleted. Where can I get the default facebook application for Nokia C6-00. I,ve Looked at many places coz ovi store doesn't have. I have checked many times. So plz tell
-
Is anyone else totally frustrated with an inability to save or print PDFs using Safari 6.0.3? I'm tired of opening a PDF in Safari to see if it's something I want to print, and then having to reopen the same PDF in Firefox or another browser to prin
-
CLIENT_CREATE_FAILED error in the Call Adapter pipeline
Hi, all. i think i've almost done the configuration of XI 3.0(CI + 2 DIs). SXI_CACHE, SLDCHECK, import of IR, ID objects ...etc. are O.K. But when i really run some scenarios of, File Adapter --> XI --> ABAP Proxy or ABAP Proxy --> XI --> J
-
Flash [?] drive not appearing in /dev/disk/by-uuid
I'm not sure if "flash drive" is the correct term or not ... the filesystem I want to mount is on a Sansa c240 MP3 player (a refurbished unit I bought last week), which connects via USB. Now, I *can* mount the drive, and have been able to all along,
-
IMovie freezes when importing AVCHD from Canon HF20
I've recently bought a *Canon HF20 AVCHD* Full HD camcorder, and am having a hard time importing the footage through iMovie '09. Here's exactly what happens: 1. I connect the USB to the back port of the iMac. The camera indicates a flashing USB symbo