Get n seconds before the target time. See Example Test Cases about the format.

Difficulty: introductory

Starter code:

def seconds_ago(s,n):
	

Solutions:
from datetime import *

def seconds_ago(s,n):
    return str(datetime.strptime(s, '%Y-%m-%d %H:%M:%S') - timedelta(seconds=n))

from datetime import datetime,timedelta

def seconds_ago(s,n):
    t = datetime.strptime(s,'%Y-%m-%d %H:%M:%S')-timedelta(seconds=n)
    return str(t.year).zfill(4)+t.strftime('-%m-%d %H:%M:%S')

from dateutil import parser
import datetime

def seconds_ago(s,n):
    timej = parser.parse(s) - datetime.timedelta(seconds=n)
    return  str(timej)

from datetime import timedelta, datetime
def seconds_ago(s,n):
#   return (datetime.fromisoformat(s) - timedelta(seconds = n)).isoformat(sep=' ')   # python ver >= 3.7
    return (datetime.strptime(s, "%Y-%m-%d %H:%M:%S") - timedelta(seconds = n)).strftime("%4Y-%m-%d %H:%M:%S")

from datetime import datetime, timedelta
def seconds_ago(s,n):
    d = datetime.strptime(s, '%Y-%m-%d %H:%M:%S')
    return str(d - timedelta(seconds = n))

from datetime import datetime, timedelta

def seconds_ago(s,n):
    return str(datetime.strptime(s, "%Y-%m-%d %H:%M:%S") - timedelta(seconds=n))

import datetime,re
seconds_ago = lambda Q,S : str(datetime.datetime(*map(int,re.split('[- :]',Q))) - datetime.timedelta(0,S))

import datetime as dt

import datetime

seconds_ago = lambda s,n: str(datetime.datetime.strptime(s, "%Y-%m-%d %H:%M:%S") - datetime.timedelta(seconds=n))

from datetime import datetime, timedelta
def seconds_ago(s, n):
    time = datetime.strptime(s, '%Y-%m-%d %H:%M:%S') - timedelta(seconds=n)
    return str(time)


import datetime

def seconds_ago(s,n):
    d = datetime.datetime.strptime(s, '%Y-%m-%d %H:%M:%S') + datetime.timedelta(seconds=-n)
    return d.strftime('%Y').rjust(4, '0') + d.strftime('-%m-%d %H:%M:%S')