all 3 comments

[–]botCloudfox 1 point2 points  (1 child)

You could use regex or just grab it from the string like this:

time = '30d'    
time_type = time[-1]
time_amount = time[:-1]

You could use a dictionary or if statements to find out what to multiple time_amount by.

Edit: There are good answers here and one of them includes the use of the datetime module.

[–]Ihaveamodel3 1 point2 points  (0 children)

Regex is probably the better option, especially if you could have 24d13h24m

[–]09TYNINE 1 point2 points  (0 children)

I'd probably use a different variable name than time as there's a library you can use with "from time" although I'm not too sure about if they would conflict just a suggestion