Friday, December 18, 2015

Convert Time to Decimal / Interger As per Our Requirements

This Post is as per Request of my Friend Shyam Pandey's .. Post

So our primary Aim is to get hours from Time Datatype Variable So that we can use it*.

Let's adapt to situation by assigning variables..
Name                   Datatype
1. GivenTime      Time
2.TimeInText      Text
3.HourTime          Integer
4.Am_Pm            Text

Let Time Be 12AM i.e

GivenTime := 00T;  //i.e 12:00:00 AM

Now Copy the Hours and convert into integer
TimeInText := FORMAT(GivenTime);

Now copy for AM/PM

Am_Pm := COPYSTR(TimeInText,10,2);

Now you got time in integers and AM/Pm in text you can test for  whatever conditions
you required..

IF (HourTime = 12) AND (Am_PM = 'AM') THEN
HourTime := 00;//but you will get only 0

So If you want to Show only 00 as Out put  take another text variable text1:= '00';

NOTE : In Case If you need to it somewhere to convert also there wont be any problem;

Saying above statement that you convert again easily
1. Integer

Time := 0T + HourTime;



So there won't be any problems.........

Thank you,