How to remove seconds and milliseconds from a date time string in python

How can I convert the date in the format "2013-03-15 05:14:51.327" to "2013-03-15 05:14" , i.e. delete seconds and milliseconds. I do not think that there is a way in the work of the robot. Please let me know if anyone has a solution for this in python.

+5
source share
2 answers

Try it (thanks Blender!)

 >>> date = "2013-03-15 05:14:51.327" >>> newdate = date.rpartition(':')[0] >>> print newdate 2013-03-15 05:14 
+4
source

In Robotframework, the easiest way would be to use a Split String From Right user from the String library library:

 ${datestring}= Set Variable 2019-03-15 05:14:51.327 ${parts}= Split String From Right ${datestring} : max_split=1 # parts is a list of two elements - everything before the last ":", and everything after it # take the 1st element, it is what we're after ${no seconds}= Get From List ${parts} 0 Log ${no senods} # 2019-03-15 05:14 
0
source

Source: https://habr.com/ru/post/1469456/


All Articles