Reformatting date to different format











up vote
-3
down vote

favorite












i need to modify the date output that i get to the format: yyyy/mm/dd



Example:



Input: Fri, 16 Nov 2018 08:46:20 +0100

Output: 2018/11/16



I've tried this code:



from datetime import datetime

datetime_object = datetime.strptime('Thu, 15 Nov 2018 15:41:36 +0100', '%b %d %Y %I:%M%p')

print(datetime_object)


But I'm getting the error ValueError: time data 'Thu, 15 Nov 2018' does not match format '%b, %d %M %Y'










share|improve this question









New contributor




joao santana is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
















  • 1




    Hi, could you please post your code as well?
    – toti08
    21 hours ago






  • 1




    Without the code that prints the date as Fri, 16 Nov 2018 08:46:20 +0100 we can't really help here. You normally format datetime objects with the datetime.strftime(), but we can't even be sure you are using datetime here.
    – Martijn Pieters
    21 hours ago










  • In which format is your date string data?
    – rv7
    20 hours ago












  • yeah, its a string
    – joao santana
    20 hours ago










  • Consistency issue: '%b %d %Y %I:%M%p' or '%b, %d %M %Y'? comma or not comma?
    – Matthieu Brucher
    12 hours ago















up vote
-3
down vote

favorite












i need to modify the date output that i get to the format: yyyy/mm/dd



Example:



Input: Fri, 16 Nov 2018 08:46:20 +0100

Output: 2018/11/16



I've tried this code:



from datetime import datetime

datetime_object = datetime.strptime('Thu, 15 Nov 2018 15:41:36 +0100', '%b %d %Y %I:%M%p')

print(datetime_object)


But I'm getting the error ValueError: time data 'Thu, 15 Nov 2018' does not match format '%b, %d %M %Y'










share|improve this question









New contributor




joao santana is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
















  • 1




    Hi, could you please post your code as well?
    – toti08
    21 hours ago






  • 1




    Without the code that prints the date as Fri, 16 Nov 2018 08:46:20 +0100 we can't really help here. You normally format datetime objects with the datetime.strftime(), but we can't even be sure you are using datetime here.
    – Martijn Pieters
    21 hours ago










  • In which format is your date string data?
    – rv7
    20 hours ago












  • yeah, its a string
    – joao santana
    20 hours ago










  • Consistency issue: '%b %d %Y %I:%M%p' or '%b, %d %M %Y'? comma or not comma?
    – Matthieu Brucher
    12 hours ago













up vote
-3
down vote

favorite









up vote
-3
down vote

favorite











i need to modify the date output that i get to the format: yyyy/mm/dd



Example:



Input: Fri, 16 Nov 2018 08:46:20 +0100

Output: 2018/11/16



I've tried this code:



from datetime import datetime

datetime_object = datetime.strptime('Thu, 15 Nov 2018 15:41:36 +0100', '%b %d %Y %I:%M%p')

print(datetime_object)


But I'm getting the error ValueError: time data 'Thu, 15 Nov 2018' does not match format '%b, %d %M %Y'










share|improve this question









New contributor




joao santana is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











i need to modify the date output that i get to the format: yyyy/mm/dd



Example:



Input: Fri, 16 Nov 2018 08:46:20 +0100

Output: 2018/11/16



I've tried this code:



from datetime import datetime

datetime_object = datetime.strptime('Thu, 15 Nov 2018 15:41:36 +0100', '%b %d %Y %I:%M%p')

print(datetime_object)


But I'm getting the error ValueError: time data 'Thu, 15 Nov 2018' does not match format '%b, %d %M %Y'







python date-formatting






share|improve this question









New contributor




joao santana is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




joao santana is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 16 hours ago









Raniz

7,97011954




7,97011954






New contributor




joao santana is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 21 hours ago









joao santana

65




65




New contributor




joao santana is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





joao santana is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






joao santana is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.








  • 1




    Hi, could you please post your code as well?
    – toti08
    21 hours ago






  • 1




    Without the code that prints the date as Fri, 16 Nov 2018 08:46:20 +0100 we can't really help here. You normally format datetime objects with the datetime.strftime(), but we can't even be sure you are using datetime here.
    – Martijn Pieters
    21 hours ago










  • In which format is your date string data?
    – rv7
    20 hours ago












  • yeah, its a string
    – joao santana
    20 hours ago










  • Consistency issue: '%b %d %Y %I:%M%p' or '%b, %d %M %Y'? comma or not comma?
    – Matthieu Brucher
    12 hours ago














  • 1




    Hi, could you please post your code as well?
    – toti08
    21 hours ago






  • 1




    Without the code that prints the date as Fri, 16 Nov 2018 08:46:20 +0100 we can't really help here. You normally format datetime objects with the datetime.strftime(), but we can't even be sure you are using datetime here.
    – Martijn Pieters
    21 hours ago










  • In which format is your date string data?
    – rv7
    20 hours ago












  • yeah, its a string
    – joao santana
    20 hours ago










  • Consistency issue: '%b %d %Y %I:%M%p' or '%b, %d %M %Y'? comma or not comma?
    – Matthieu Brucher
    12 hours ago








1




1




Hi, could you please post your code as well?
– toti08
21 hours ago




Hi, could you please post your code as well?
– toti08
21 hours ago




1




1




Without the code that prints the date as Fri, 16 Nov 2018 08:46:20 +0100 we can't really help here. You normally format datetime objects with the datetime.strftime(), but we can't even be sure you are using datetime here.
– Martijn Pieters
21 hours ago




Without the code that prints the date as Fri, 16 Nov 2018 08:46:20 +0100 we can't really help here. You normally format datetime objects with the datetime.strftime(), but we can't even be sure you are using datetime here.
– Martijn Pieters
21 hours ago












In which format is your date string data?
– rv7
20 hours ago






In which format is your date string data?
– rv7
20 hours ago














yeah, its a string
– joao santana
20 hours ago




yeah, its a string
– joao santana
20 hours ago












Consistency issue: '%b %d %Y %I:%M%p' or '%b, %d %M %Y'? comma or not comma?
– Matthieu Brucher
12 hours ago




Consistency issue: '%b %d %Y %I:%M%p' or '%b, %d %M %Y'? comma or not comma?
– Matthieu Brucher
12 hours ago

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});






joao santana is a new contributor. Be nice, and check out our Code of Conduct.










 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53370909%2freformatting-date-to-different-format%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes








joao santana is a new contributor. Be nice, and check out our Code of Conduct.










 

draft saved


draft discarded


















joao santana is a new contributor. Be nice, and check out our Code of Conduct.













joao santana is a new contributor. Be nice, and check out our Code of Conduct.












joao santana is a new contributor. Be nice, and check out our Code of Conduct.















 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53370909%2freformatting-date-to-different-format%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

404 Error Contact Form 7 ajax form submitting

How to know if a Active Directory user can login interactively

TypeError: fit_transform() missing 1 required positional argument: 'X'