![]() |
|
[Python] strftime subtracting time - Printable Version +- Hack Forums (https://hackforums.net) +-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444) +--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151) +---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118) +---- Thread: [Python] strftime subtracting time (/showthread.php?tid=5929633) |
strftime subtracting time - Lockheed - Jan 14, 2019 Hey HF, long time no see. Got a script which i need to subtract 25 minutes from, essentially at the moment data is being gathered from a SQL database when being input/plotted into an Excel spreadsheet. The time on the spreadsheet needs to be 25 minutes sooner than what the SQL Database outputs - What i've got at the moment is below. PHP Code Can't seem to find any documentation on strftime which explains what i want, i assume it needs to look something like the below, although its not working: PHP Code Any suggestions? TIA 🤝 RE: strftime subtracting time - lockhead - Jan 15, 2019 (Jan 14, 2019 06:10 PM)Lockheed Wrote: Hey HF, long time no see. First of all nice name 🤝 You can find info on strftime here: https://docs.python.org/2/library/datetime.html#strftime-strptime-behavior http://strftime.org/ But I'm not entirely sure what you're trying to do. Do you want to take the current time (the time the script is being executed) and subtract 25 minutes from it, then write it into a spreadsheet? Or get a time from a SQL DB then sub 25 mins from that and write it into a spreadsheet? Either way strftime() won't really help you there, it only gives you a string representation of a date object in a specified format. And "-15M" isn't a format specifier. I think what you need is the timedelta() function (also documented in the link above). Code from datetime import datetimeRE: strftime subtracting time - Lockheed - Jan 15, 2019 (Jan 15, 2019 03:29 AM)lockhead Wrote: First of all nice name 🤝 Ha, thanks. Will look into it - thanks for the code you included :) |