increment a date by one day for 15 days.
up vote
-2
down vote
favorite
Why don't I get any results from this code. Can you please help me.
from datetime import datetime, timedelta
myStr = '20170817'
dateObj = datetime.strptime(myStr, '%Y%m%d')
timeStep = timedelta(days=1)
def Days15(myStr):
dateList = [dateObj + timeStep*i for i in range(15)]
return dateList
python
New contributor
|
show 1 more comment
up vote
-2
down vote
favorite
Why don't I get any results from this code. Can you please help me.
from datetime import datetime, timedelta
myStr = '20170817'
dateObj = datetime.strptime(myStr, '%Y%m%d')
timeStep = timedelta(days=1)
def Days15(myStr):
dateList = [dateObj + timeStep*i for i in range(15)]
return dateList
python
New contributor
Do you get an error message? Or do you get an output at all? What do you expect or hope to happen?
– Alex_P
Nov 10 at 19:14
2
Your code works, but you're not actually printing anything out. Throw aprint Days15(myStr)
at the end of your code and you'll see 15 date objects
– ahota
Nov 10 at 19:16
When saying you don't get "any results", it helps to give an example of input and expected output pair. You created a function called Days15, which you are not calling. Please use lower case name for functions. Also, it looks to me you don't need a function in this example.
– Mircea
Nov 10 at 19:18
Thank you. I've tried putting in the print Days15(myStr) in different sections but it's giving me a syntax error. Where do I put the pring command in?
– Nathan
Nov 10 at 19:24
also, here is the results I'm trying to get: [datetime.datetime(2017, 8, 17, 0, 0), datetime.datetime(2017, 8, 18, 0, 0), datetime.datetime(2017, 8, 19, 0, 0), datetime.datetime(2017, 8, 20, 0, 0), datetime.datetime(2017, 8, 21, 0, 0), datetime.datetime(2017, 8, 22, 0, 0), datetime.datetime(2017, 8, 23, 0, 0), datetime.datetime(2017, 8, 24, 0, 0), datetime.datetime(2017, 8, 25, 0, 0), datetime.datetime(2017, 8, 26, 0, 0), datetime.datetime(2017, 8, 27, 0, 0), datetime.datetime(2017, 8, 28, 0, 0), datetime.datetime(2017, 8, 29, 0, 0), datetime.datetime(2017, 8, 30, 0, 0), datetime.datetime(2017
– Nathan
Nov 10 at 19:25
|
show 1 more comment
up vote
-2
down vote
favorite
up vote
-2
down vote
favorite
Why don't I get any results from this code. Can you please help me.
from datetime import datetime, timedelta
myStr = '20170817'
dateObj = datetime.strptime(myStr, '%Y%m%d')
timeStep = timedelta(days=1)
def Days15(myStr):
dateList = [dateObj + timeStep*i for i in range(15)]
return dateList
python
New contributor
Why don't I get any results from this code. Can you please help me.
from datetime import datetime, timedelta
myStr = '20170817'
dateObj = datetime.strptime(myStr, '%Y%m%d')
timeStep = timedelta(days=1)
def Days15(myStr):
dateList = [dateObj + timeStep*i for i in range(15)]
return dateList
python
python
New contributor
New contributor
New contributor
asked Nov 10 at 19:13
Nathan
11
11
New contributor
New contributor
Do you get an error message? Or do you get an output at all? What do you expect or hope to happen?
– Alex_P
Nov 10 at 19:14
2
Your code works, but you're not actually printing anything out. Throw aprint Days15(myStr)
at the end of your code and you'll see 15 date objects
– ahota
Nov 10 at 19:16
When saying you don't get "any results", it helps to give an example of input and expected output pair. You created a function called Days15, which you are not calling. Please use lower case name for functions. Also, it looks to me you don't need a function in this example.
– Mircea
Nov 10 at 19:18
Thank you. I've tried putting in the print Days15(myStr) in different sections but it's giving me a syntax error. Where do I put the pring command in?
– Nathan
Nov 10 at 19:24
also, here is the results I'm trying to get: [datetime.datetime(2017, 8, 17, 0, 0), datetime.datetime(2017, 8, 18, 0, 0), datetime.datetime(2017, 8, 19, 0, 0), datetime.datetime(2017, 8, 20, 0, 0), datetime.datetime(2017, 8, 21, 0, 0), datetime.datetime(2017, 8, 22, 0, 0), datetime.datetime(2017, 8, 23, 0, 0), datetime.datetime(2017, 8, 24, 0, 0), datetime.datetime(2017, 8, 25, 0, 0), datetime.datetime(2017, 8, 26, 0, 0), datetime.datetime(2017, 8, 27, 0, 0), datetime.datetime(2017, 8, 28, 0, 0), datetime.datetime(2017, 8, 29, 0, 0), datetime.datetime(2017, 8, 30, 0, 0), datetime.datetime(2017
– Nathan
Nov 10 at 19:25
|
show 1 more comment
Do you get an error message? Or do you get an output at all? What do you expect or hope to happen?
– Alex_P
Nov 10 at 19:14
2
Your code works, but you're not actually printing anything out. Throw aprint Days15(myStr)
at the end of your code and you'll see 15 date objects
– ahota
Nov 10 at 19:16
When saying you don't get "any results", it helps to give an example of input and expected output pair. You created a function called Days15, which you are not calling. Please use lower case name for functions. Also, it looks to me you don't need a function in this example.
– Mircea
Nov 10 at 19:18
Thank you. I've tried putting in the print Days15(myStr) in different sections but it's giving me a syntax error. Where do I put the pring command in?
– Nathan
Nov 10 at 19:24
also, here is the results I'm trying to get: [datetime.datetime(2017, 8, 17, 0, 0), datetime.datetime(2017, 8, 18, 0, 0), datetime.datetime(2017, 8, 19, 0, 0), datetime.datetime(2017, 8, 20, 0, 0), datetime.datetime(2017, 8, 21, 0, 0), datetime.datetime(2017, 8, 22, 0, 0), datetime.datetime(2017, 8, 23, 0, 0), datetime.datetime(2017, 8, 24, 0, 0), datetime.datetime(2017, 8, 25, 0, 0), datetime.datetime(2017, 8, 26, 0, 0), datetime.datetime(2017, 8, 27, 0, 0), datetime.datetime(2017, 8, 28, 0, 0), datetime.datetime(2017, 8, 29, 0, 0), datetime.datetime(2017, 8, 30, 0, 0), datetime.datetime(2017
– Nathan
Nov 10 at 19:25
Do you get an error message? Or do you get an output at all? What do you expect or hope to happen?
– Alex_P
Nov 10 at 19:14
Do you get an error message? Or do you get an output at all? What do you expect or hope to happen?
– Alex_P
Nov 10 at 19:14
2
2
Your code works, but you're not actually printing anything out. Throw a
print Days15(myStr)
at the end of your code and you'll see 15 date objects– ahota
Nov 10 at 19:16
Your code works, but you're not actually printing anything out. Throw a
print Days15(myStr)
at the end of your code and you'll see 15 date objects– ahota
Nov 10 at 19:16
When saying you don't get "any results", it helps to give an example of input and expected output pair. You created a function called Days15, which you are not calling. Please use lower case name for functions. Also, it looks to me you don't need a function in this example.
– Mircea
Nov 10 at 19:18
When saying you don't get "any results", it helps to give an example of input and expected output pair. You created a function called Days15, which you are not calling. Please use lower case name for functions. Also, it looks to me you don't need a function in this example.
– Mircea
Nov 10 at 19:18
Thank you. I've tried putting in the print Days15(myStr) in different sections but it's giving me a syntax error. Where do I put the pring command in?
– Nathan
Nov 10 at 19:24
Thank you. I've tried putting in the print Days15(myStr) in different sections but it's giving me a syntax error. Where do I put the pring command in?
– Nathan
Nov 10 at 19:24
also, here is the results I'm trying to get: [datetime.datetime(2017, 8, 17, 0, 0), datetime.datetime(2017, 8, 18, 0, 0), datetime.datetime(2017, 8, 19, 0, 0), datetime.datetime(2017, 8, 20, 0, 0), datetime.datetime(2017, 8, 21, 0, 0), datetime.datetime(2017, 8, 22, 0, 0), datetime.datetime(2017, 8, 23, 0, 0), datetime.datetime(2017, 8, 24, 0, 0), datetime.datetime(2017, 8, 25, 0, 0), datetime.datetime(2017, 8, 26, 0, 0), datetime.datetime(2017, 8, 27, 0, 0), datetime.datetime(2017, 8, 28, 0, 0), datetime.datetime(2017, 8, 29, 0, 0), datetime.datetime(2017, 8, 30, 0, 0), datetime.datetime(2017
– Nathan
Nov 10 at 19:25
also, here is the results I'm trying to get: [datetime.datetime(2017, 8, 17, 0, 0), datetime.datetime(2017, 8, 18, 0, 0), datetime.datetime(2017, 8, 19, 0, 0), datetime.datetime(2017, 8, 20, 0, 0), datetime.datetime(2017, 8, 21, 0, 0), datetime.datetime(2017, 8, 22, 0, 0), datetime.datetime(2017, 8, 23, 0, 0), datetime.datetime(2017, 8, 24, 0, 0), datetime.datetime(2017, 8, 25, 0, 0), datetime.datetime(2017, 8, 26, 0, 0), datetime.datetime(2017, 8, 27, 0, 0), datetime.datetime(2017, 8, 28, 0, 0), datetime.datetime(2017, 8, 29, 0, 0), datetime.datetime(2017, 8, 30, 0, 0), datetime.datetime(2017
– Nathan
Nov 10 at 19:25
|
show 1 more comment
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Nathan is a new contributor. Be nice, and check out our Code of Conduct.
draft saved
draft discarded
Nathan is a new contributor. Be nice, and check out our Code of Conduct.
Nathan is a new contributor. Be nice, and check out our Code of Conduct.
Nathan is a new contributor. Be nice, and check out our Code of Conduct.
draft saved
draft discarded
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%2f53242510%2fincrement-a-date-by-one-day-for-15-days%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
Do you get an error message? Or do you get an output at all? What do you expect or hope to happen?
– Alex_P
Nov 10 at 19:14
2
Your code works, but you're not actually printing anything out. Throw a
print Days15(myStr)
at the end of your code and you'll see 15 date objects– ahota
Nov 10 at 19:16
When saying you don't get "any results", it helps to give an example of input and expected output pair. You created a function called Days15, which you are not calling. Please use lower case name for functions. Also, it looks to me you don't need a function in this example.
– Mircea
Nov 10 at 19:18
Thank you. I've tried putting in the print Days15(myStr) in different sections but it's giving me a syntax error. Where do I put the pring command in?
– Nathan
Nov 10 at 19:24
also, here is the results I'm trying to get: [datetime.datetime(2017, 8, 17, 0, 0), datetime.datetime(2017, 8, 18, 0, 0), datetime.datetime(2017, 8, 19, 0, 0), datetime.datetime(2017, 8, 20, 0, 0), datetime.datetime(2017, 8, 21, 0, 0), datetime.datetime(2017, 8, 22, 0, 0), datetime.datetime(2017, 8, 23, 0, 0), datetime.datetime(2017, 8, 24, 0, 0), datetime.datetime(2017, 8, 25, 0, 0), datetime.datetime(2017, 8, 26, 0, 0), datetime.datetime(2017, 8, 27, 0, 0), datetime.datetime(2017, 8, 28, 0, 0), datetime.datetime(2017, 8, 29, 0, 0), datetime.datetime(2017, 8, 30, 0, 0), datetime.datetime(2017
– Nathan
Nov 10 at 19:25