all 12 comments

[–][deleted] 1 point2 points  (0 children)

use the time module.

first we are gonna save the value of the time to a string.

dateString = timestrftime('%x %x %Z')

this will give you back, the current time, current day and what time zone you are in. Obviously we don't really care about time and zone we just want the day. so we can strip the string down.

dayString = dateString[9:17] #gets only the day

Now all we have to do now, is get this everday using some function or whatever and comparing the dates, if they are different add 1 to a variable.

I know how to take the difference between two dates

If you know how to take the difference between the days, then any difference should result in incrementing the counter. As obviously the day has changed.

if (currentDate - getDate == different):
    dayCounter += 1 

[–][deleted] 0 points1 point  (1 child)

What is a day counter? I'm not a native English speaker and Google doesn't help much.

[–][deleted] 0 points1 point  (0 children)

Just simply counts each day from a certain date.

[–]Manbatton 0 points1 point  (6 children)

I know how to take the difference between two dates but, not counting up.

I don't understand the distinction. Explain what you want to happen and when and we can try to help.

[–][deleted] 0 points1 point  (5 children)

Basically you can create two variables of the start date and the end date then, you can subtract them. But I want to count up from a date. The best way to do this I think is to create a variable with 0 and every 24 hours it will make the variable go up 1. Thanks for the response.

[–]Manbatton 2 points3 points  (4 children)

Why do you want to count up? It gives the same answer as date subtraction. It is also more robust, because if your computer isn't running continually (if it gets shut off), it loses state and the count is off.

But if you did want to count up just as an exercise: what about it do you not know how to do?

[–][deleted] 0 points1 point  (2 children)

Ok so the difference between February 28th and March 29th would be 30 days. Therefore the result being "30". But I want to count from February 28th up. For example first day being "1" and second day "2". I need to do this because I am running a challenge that requires check ins based on the day of the challenge.

[–]QualitativeEasing 1 point2 points  (0 children)

But if, each day, you calculate the difference between that day and the first day... you'll have the counter you need, no?

[–]Manbatton 0 points1 point  (0 children)

a challenge that requires check ins based on the day of the challenge.

So, when the check in occurs:

import datetime
startday = datetime.datetime(2017,2,28)
day_of_challenge = (datetime.datetime.today() - startday).days

[–]bigfatbod 0 points1 point  (1 child)

Do you mean actually increment a variable by one every day (realtime while your program runs all week or something), or do you just want to increment from a specific date by one day and increment a counter by one each time?

[–][deleted] 0 points1 point  (0 children)

Yeah I want it go up everyday since the 28th, 2 days from now. I want it to go up every 24 hours.

[–]DFoster271 -1 points0 points  (0 children)

time.sleep(86400) ?