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

Convert float to date

david_fryda2
Participant
0 Kudos
6,434

Hello everyone,

I need to convert "2.006123100000000E+07" to a date format.

How can I do it ?

Thanks in advance.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Kudos
2,262

Hello David,

You could it like this:

DATA:

zlv_float TYPE f VALUE '2.006123100000000E+07',

zlv_integer TYPE i,

zlv_date TYPE d.

zlv_integer = zlv_float.

write zlv_integer to zlv_date.

Regards,

John.

11 REPLIES 11
Read only

rahulkavuri
Active Contributor
0 Kudos
2,262

JUST EDITED THIS ONE, NOW U GET THE VALUE INTO THE STRING>>>


REPORT GEN.
DATA : float TYPE f.

DATA : string(15) TYPE c.

float = '21.12345'.

CALL FUNCTION 'FLTP_CHAR_CONVERSION'
EXPORTING
DECIM = 0
* EXPON = 0
input = float
* IVALU = ' '
* MASKN = ' '
IMPORTING
flstr = string
.

WRITE :/ float.
WRITE :/ string.

Read only

0 Kudos
2,262

Hi Rahul,

If I put the following float "2.006123100000000E+07" instead "41.356661234", it gives me a dump.

Thanks.

Read only

Former Member
0 Kudos
2,263

Hello David,

You could it like this:

DATA:

zlv_float TYPE f VALUE '2.006123100000000E+07',

zlv_integer TYPE i,

zlv_date TYPE d.

zlv_integer = zlv_float.

write zlv_integer to zlv_date.

Regards,

John.

Read only

0 Kudos
2,262

Thanks John,

It works.

Here are the rewards....

Enjoy

Read only

0 Kudos
2,262

Hi John,

Looks good logic but when i give the f value '2.006123200000000E+07' it is printing the date as

32122006. This date is not valid

Hope we need to validate the date while conversion.

DATA:

zlv_float TYPE f VALUE '2.006123200000000E+07',

zlv_integer TYPE i,

zlv_date TYPE d.

zlv_integer = zlv_float.

write zlv_integer to zlv_date.

write zlv_date.

Read only

0 Kudos
2,262

HI PLEASE TRY OUT WITH THE CODE I HAVE GIVEN, IT WORKS PERFECTLY ACCORDING TO THE REQUIREMENT

BY THE WAY THIS IS JUST THE WAY TO GET FLOAT INTO ANOTHER VARIABLE... IF U WANT THAT TO BE VERIFIED THEN U NEED TO DO THAT MANUALLY USING SOME CODE

Read only

0 Kudos
2,262

Hi Aluru,

Just add 'DD/MM/YYYY' and you will get a perfect date:

write zlv_date dd/mm/yyyy.

John.

Read only

2,262
REPORT  ychatest                                .

DATA : p_float TYPE f,
       p_date LIKE cawn-atwrt,
       p_flt LIKE cawn-atflv,
       p_dt LIKE sy-datum.
.

p_float = '2.006123100000000E+07'.
p_flt = p_float.

CALL FUNCTION 'CTCV_CONVERT_FLOAT_TO_DATE'
  EXPORTING
    float = p_flt
  IMPORTING
    date  = p_date.

WRITE : p_date TO p_dt DD/MM/YYYY.

WRITE : p_dt.
Read only

Former Member
0 Kudos
2,262

hi ,

use convert key word.

that is

syntax

CONVERT TIME STAMP tst TIME ZONE tz INTO DATE d TIME t.

Example

CONVERT TIME STAMP lv_timestamp TIME ZONE SY-ZONLO INTO DATE d TIME t.

lv_timestamp type should be TIMESTAMP or TIMESTAMPL,

Mark Helpfull answers

Reagrds

Mark Helfull answers.

Read only

2,262

Hi david,

try CTCV_CONVERT_FLOAT_TO_DATE.

regards,

Suresh Datti

Read only

erovneiko
Discoverer
2,262
date = CONV char8( CONV i( float ) ).