Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

caculate date

Former Member
0 Likes
1,148

hi experts

how do i claculate from sy-datum a date that is a year before

tahnks

amit

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,110

hi,

follow this code

DATA:date1 type sy-datum.

date1 = sy-datum.

date1 = date1 - 365.

write:date1.

10 REPLIES 10
Read only

Former Member
0 Likes
1,110

hi,

try this

data date like sy-datum.

date = sy-datum

w_date = date+0(4).

subtract 1 from w_date.

date+0(4) = w_date.

write:/ date.

Hope this will help.

Regards

Sumit Agarwal

Read only

Former Member
0 Likes
1,110

Hi,

Use any of the following FMs for dates :

Check these FM's:

HR_HK_DIFF_BT_2_DATES

HR_99S_INTERVAL_BETWEEN_DATES

Hope this helps!!!

Regards,

Lalit

Read only

Former Member
0 Likes
1,110

Hi,

Get the year from sy-datum

lv_year = sy-datum+(4)

lv_year = lv_year - 1

concatenate lv_year '.' sy-datum4(2)' .' sy-datum6(2) INTO

lv_new_date.

Read only

Former Member
0 Likes
1,110

Just put a logic,

use like this:

temp = sy-datum+0(4) - 1

for getting a previous year.

than concatenate again.

concatenate temp sy-datum+2(2) sy-datum+4(2) temp into sy-datum

Amit.

Read only

Former Member
0 Likes
1,111

hi,

follow this code

DATA:date1 type sy-datum.

date1 = sy-datum.

date1 = date1 - 365.

write:date1.

Read only

Former Member
0 Likes
1,110

Hi Amit,

data: w_yr like sy-datum

w_yr1 like sy-datum.

w_yr = sy-datum(4)

w_yr =w_yr - 1

concatenate w_yr sy-datum4(2) sy-datum6(2) INTO w_yr1.

Hope this helps you.

Regards,

Chandra Sekhar

Read only

Former Member
0 Likes
1,110

Hi Amit,

refer to the code below:

parameters:
  p_datum type sy-datum.

data:
  w_datum(4) type c.

w_datum = p_datum+0(4) - 1.

p_datum+0(4) = w_datum.

write: p_datum.

or you can do sumthing like:

parameters:
  p_datum type sy-datum.

p_datum = p_datum - 365.

write: p_datum .

With luck,

Pritam.

Read only

Former Member
0 Likes
1,110

Hi,

hope this code helps u,

&----


*& Report ZTESTDATETWO

*&

&----


*&

*&

&----


REPORT ZTESTDATETWO.

data:locdate type sy-datum, "locdate is used to store the current date.

locmonth(2) type c, "locmonth is used to store the month of the date.

locyear(4) type c, "locyear is used to store the year of the date.

locday(2) type c, "locday is used to store the day of the year.

locconca(10) type c. "locconca is used to store the date in dd-mm-yyyy.

locdate = sy-datum. "the current date is assigned to variable locdate.

locyear = locdate+0(4).

subtract 1 from locyear. "the year of the date is stored in the variable locyear.

locmonth = locdate+4(2). "the month of the date is stored in the variable locmonth.

locday = locdate+6(2). "the day of the date is stored in the variable locday.

concatenate locday locmonth locyear into locconca separated by '-'. "concatinating the year,month and day from thier respective variables into a variable locconca.

write:locconca.

Thanks & regards,

Sravani Yendru.

Read only

Former Member
0 Likes
1,110

Hii,

check this out, this may work for each and every calculation of date in which ever format you want.

data: day type char2,

mnth type char2,

yr type char4,

date type char10.

day = sy-datum+6(2).

mnth = sy-datum+4(2).

yr = sy-datum+0(4).

CONCATENATE day mnth yr INTO date separated by '.'.

write: / date.

Read only

Former Member
0 Likes
1,110

Hi,

The best way to calculate date is.

Suppose today is 14.07.2008 and you want 14.07.2007

Data: dat1 type sy-datum,

gdat1(8) type n,

gdat2(8) type n ,

datfinal type sy-datum.

dat1 = sy-datum.

Now dat1 will have 20080714.

gdat1 = '99999999' - dat1.

gdat1 will have 79919285.

gdat2 = gdat1 + 10000

gdat2 will have 79929285.

datfinal = '99999999' - 79929285.

Datfinal will have 20070714.

Hope this will help you.

Reward points if you find it useful.

Regards,

Adi