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'
python date-formatting
New contributor
|
show 2 more comments
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'
python date-formatting
New contributor
1
Hi, could you please post your code as well?
– toti08
21 hours ago
1
Without the code that prints the date asFri, 16 Nov 2018 08:46:20 +0100
we can't really help here. You normally formatdatetime
objects with thedatetime.strftime()
, but we can't even be sure you are usingdatetime
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
|
show 2 more comments
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'
python date-formatting
New contributor
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
python date-formatting
New contributor
New contributor
edited 16 hours ago
Raniz
7,97011954
7,97011954
New contributor
asked 21 hours ago
joao santana
65
65
New contributor
New contributor
1
Hi, could you please post your code as well?
– toti08
21 hours ago
1
Without the code that prints the date asFri, 16 Nov 2018 08:46:20 +0100
we can't really help here. You normally formatdatetime
objects with thedatetime.strftime()
, but we can't even be sure you are usingdatetime
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
|
show 2 more comments
1
Hi, could you please post your code as well?
– toti08
21 hours ago
1
Without the code that prints the date asFri, 16 Nov 2018 08:46:20 +0100
we can't really help here. You normally formatdatetime
objects with thedatetime.strftime()
, but we can't even be sure you are usingdatetime
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
|
show 2 more comments
active
oldest
votes
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.
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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 formatdatetime
objects with thedatetime.strftime()
, but we can't even be sure you are usingdatetime
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