Second, to your specific problem: You can take differnces between times and dates by first converting to timestamps, i.e.To avoid the interference of timezones, you can use the -gmt flag.
Tcl Program To Calculate The Time Difference Between Two Times Full For TimesRemember that timezones are only usefull for times, but not for dates. Tcl Program To Calculate The Time Difference Between Two Times Code Ahead SetSo I think something like this should work: warning, untested code ahead set t1 clock scan t1string -gmt 1 set t2 clock scan t2string -gmt 1 set diffinseconds expr t2 - t1 set diffindays expr diffinseconds 60 60 24 Things get more complicated, if you want the differences in months or years. Its going to be used in a larger program that will store the returned value in a database. Good job there However, there are a couple of typos in the examples. The function requires strings as input but the examples use ints. For example timedifference(1100, 1310) should be timedifference(1100, 1310). A tool like doctest can help you check for mistakes like this automatically. You are right to document the types expected by the function but after that I would just use the objects as if they are the right type and let python throw an error if they arent. I say this because type checking often gets in the way of duck typing and reduces the flexibility and generality of your code. For example, in python 2.x, isinstance(timestart, str) returns False for unicode strings ( isinstance(timestart, basestring) is a better alternative). You can just place assert statements right on the beginning of your function which check if the time parameters are valid and then just compare them. Provide details and share your research But avoid Asking for help, clarification, or responding to other answers. MathJax reference. To learn more, see our tips on writing great answers. Not the answer youre looking for Browse other questions tagged python mathematics or ask your own question.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |