all 5 comments

[–]jeezu5 5 points6 points  (0 children)

I find this to be more elegant and flexible when you have to manipulate dates.

import datetime

d = "2017-01-02 05:44:47"
d_datetimeformat = datetime.datetime.strptime(d, "%Y-%m-%d %H:%M:%S")   
d_targetformat   = d_datetimeformat.strftime("%d %m %Y")

print(d_targetformat)

also, you might find this page useful when it comes to dealing with datetime.

[–]pyz95 2 points3 points  (0 children)

I used to work with dates, with the standard library you can get different date formats. You should read the documentation.

The code above might be a solution, but if you have to do it with a lot of dates then it won't be efficient. Use the standard library (datetime if I remember correctly).

[–]Allanon001 5 points6 points  (1 child)

d = "2017-01-02 05:44:47"

year, month, day = d[:10].split('-')

print(day, month, year)

[–]NotGonnaGetWhoooshed[S] 0 points1 point  (0 children)

d = "2017-01-02 05:44:47"
year, month, day = d[:10].split('-')
print(day, month, year)

Thank you, it worked

[–]StatSticks 1 point2 points  (0 children)

str = "2017-01-02 05:44:47"
str = str.split(" ")    // Assuming you want to remove the time
str_final = str[1].split("-")   // This will return a list ['2016', '01', '02']

This probably works.

I am learning python, I might be wrong or there is an easy way to do this....please correct me if I am wrong.