Application Development 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: 

Convert float to date

david_fryda2
Participant
0 Kudos
5,208

Hello everyone,

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

How can I do it ?

Thanks in advance.

1 ACCEPTED SOLUTION

Former Member
0 Kudos
1,036

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

rahulkavuri
Active Contributor
0 Kudos
1,036

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.

0 Kudos
1,036

Hi Rahul,

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

Thanks.

Former Member
0 Kudos
1,037

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.

0 Kudos
1,036

Thanks John,

It works.

Here are the rewards....

Enjoy

0 Kudos
1,036

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.

0 Kudos
1,036

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

0 Kudos
1,036

Hi Aluru,

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

write zlv_date dd/mm/yyyy.

John.

1,036
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.

Former Member
0 Kudos
1,036

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.

1,036

Hi david,

try CTCV_CONVERT_FLOAT_TO_DATE.

regards,

Suresh Datti

erovneiko
Discoverer
1,036
date = CONV char8( CONV i( float ) ).