logo
Tags down

shadow

Counting down to a time?


By : Kirill Dorogan
Date : August 02 2020, 12:00 PM
This might help you First off, there is no need to pass strings around. If you start with TTime and convert to TTime, then simply pass TTime around.
Second, since you are dealing with just time values, if the target time is meant to be on the next day, you need to add 24 hours so that you have a TDateTime that actually represents the next day.
code :
uses
  ..., DateUtils;

function TimeDiffStr(const t1, t2: TTime): string;
var
  d1, d2: TDateTime;
  secs: Int64;
begin
  d1 := t1;
  if t2 < t1 then
    d2 := IncDay(t2) // or IncHour(t2, 24)
  else
    d2 := t2; 
  secs := SecondsBetween(d1, d2);
  Result := Format('%2.2d:%2.2d:%2.2d', [secs div 3600, (secs div 60) mod 60, secs mod 60]);
end;

procedure TForm1.Timer1Timer(Sender: TObject);
var
  TargetTime: TTime;
  s: string;
begin
  TargetTime := ...;
  s := TimeDiffStr(Time(), TargetTime);
end;


Share : facebook icon twitter icon

Is there a way to delete a row from mysql after a certain amount of time counting from insert time


By : Joel Ferreira
Date : March 29 2020, 07:55 AM
seems to work fine If you have your mySQL version >= 5.1.6 , there is a good feature intended for use in such cases - mySQL events.
Here is an example of usage - http://phpmaster.com/working-with-mysql-events/

time() is counting down instead of counting upwards


By : null
Date : March 29 2020, 07:55 AM
wish help you to fix your issue I'm trying to make a lastlogin function which my gaming server saves (Unix), happily that works but instead of my time script counting up, it's going down and also goes to minus eventually.
code :
$last = time() - $row['lastlogin'];

pandas counting remaining time according to arbitrary time periods


By : user1551419
Date : March 29 2020, 07:55 AM
Any of those help One approach is to create a small function to apply to the dataframe index and compute offsets (as a row) for each of the rolling dates.
code :
def map_offsets(x):
    '''Calculate the day offsets'''
    days = [x for x in (pd_rolling - x).days if x >= 0]
    days += [np.nan] * (len(pd_rolling) - len(days))

    return [days[i] for i in periods_offsets]

df = pd.DataFrame({'dates': pd.date_range('2017-01-01', periods=8, freq='1d')}).set_index('dates')

# the inclusive ends of the time periods
rolling_dates = ['2017-01-02', '2017-01-05', '2017-01-07', '2017-01-08']

# the remaining time periods columns
periods_offsets = [0, 1, 2]

# Added: Casting to datetime will make offset calculation easier
pd_rolling = pd.to_datetime(rolling_dates)

# Create new column names for periods
fmt = 'periods_expiry_days_{}'
columns = [fmt.format(x) for x in periods_offsets]

# Subtract index from rolling date values, and add to dataframe
df[columns] = pd.DataFrame(df.index.map(map_offsets).tolist(), index=df.index)

Counting number of first time binary indicators in a time series


By : bash.d
Date : March 29 2020, 07:55 AM
Any of those help By defining a custom new function and using DataFrame.expanding. I'm not sure why the result of expanding().apply(new) requires casting from float to int, but hey, it works:
code :
def new(column):
    return column[-1] and not any(column[:-1])

result = df.expanding().apply(new).sum(axis=1).astype(int)

print(result)

Out:
11/30/2015    4
12/31/2015    3
1/31/2016     0
2/29/2016     3
3/31/2016     0
4/30/2016     0
5/31/2016     0
dtype: int32

COUNTIF formula - Counting number of occurrences a particular time occurs between two time intervals


By : user3552861
Date : March 29 2020, 07:55 AM
this will help If you can add an additional column with a time fraction of the 'Input date / time' column, you can use the following formula:
code :
=SUMPRODUCT(--($C$2:$C$6>E2),--($C$2:$C$6<F2))
=TIME(HOUR(B2),MINUTE(B2), SECOND(B2))
shadow
Privacy Policy - Terms - Contact Us © voile276.org