How to make a HMS2TIME?

pdjpdj Member Posts: 643
edited 2004-07-13 in Navision Attain
I need a function like the DMY2DATE, just for TIME variables.
There is no problem in just making a simple function like this:
Function:HMS2TIME(Hour : Code[2];Minute : Code[2];Second : Code[2]) Time : Time
EVALUATE(Time,Hour+':'+Minute+':'+Second);
But how do I insure that it works for all imaginable reginal setting?
It seems to be possible to do like this:
Time := 123012T;
But not like this:
EVALUATE(Time,'123012T');
I can see that 4.00 introduce a new parameter for EVALUATE to solve the problem, but what should I do for 3.60?

Thanks in advance
Regards
Peter

Comments

  • fbfb Member Posts: 246
    I believe this will work for all regional settings, if you take care to provide exactly 6 digits, and presuming the hour is supplied in (or converted to) 24hour form:
    EVALUATE(Time,'123012');
    
  • eksekjeksekj Member Posts: 4
    You want to get sure for formating the time in right format.
    so you should define this format
    like

    Time:= format(<hours24,2>,<minutes,2>,<seconds,2>);
    or in what format you really want to do this.

    maybe need to use <filter character> to obtain perfectly
  • i4tosti4tost Member Posts: 208
    If you want to have a possibility to convert three integer variables ti time, use arithmetic functions like
    TimeVar := 000000T + ((Hours * 60 + Minutes) * 60 + Seconds) * 1000 + miliSeconds;
    To be sure that get a correct hour, minute... variable values check them.
  • pdjpdj Member Posts: 643
    fb> It seems to work. Thanks.
    eksekj> How can I use FORMAT from Text to Time? I thougt it was only the opposite..
    i4tost> Seems to work as well. Thanks.

    I actually have milliseconds as well, so I will use i4tost's method, but thanks to all of you :-)
    Regards
    Peter
Sign In or Register to comment.