Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![Shezan Kazi](https://secure.gravatar.com/avatar/d14b629d6c6869ffa752b536a1803252?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Shezan Kazi
10,807 PointsPython 3 - timestamp from today morning 00:00:00
Hi,
how would I get the timestamp for today morning midnight? I can't seem to get this done..
Thanks!
![Shezan Kazi](https://secure.gravatar.com/avatar/d14b629d6c6869ffa752b536a1803252?s=60&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Shezan Kazi
10,807 PointsHi Ken,
I use this code to get today's date and time for midnight and end of day
import datetime
# defining global variables
today = datetime.datetime.now()
today_morning = today.strftime('%Y%m%d') + "000000"
today_evening = today.strftime('%Y%m%d') + "235959"
What I need is to display a unix timestamp for these times e.g.: 20161019000000 --> 1476835200
2 Answers
![Ken Alger](https://secure.gravatar.com/avatar/cf2cad7e6e37acacfa5201068856ed3d?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Ken Alger
Treehouse TeacherShezan;
You could use the timestamp()
method.
import datetime
dt = datetime.datetime.now().timestamp()
Will assign an Unix timestamp value to dt
. You could also do something like:
import datetime
dt = datetime.datetime.now().strftime('%s')
Is that what you are wanting? You might also want to take into consideration time zones, depending on your use case.
Post back with further questions and happy coding,
Ken
![Shezan Kazi](https://secure.gravatar.com/avatar/d14b629d6c6869ffa752b536a1803252?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Shezan Kazi
10,807 PointsHi Ken, I did try those, so thanks for your tips. However timestamp only delivers the timestamp for this very second. I, however, want the timestamp for start and beginning of the day, i.e. 00:00:00 and 23:59:59 o'clock.
That's where I'm stuck.
Ken Alger
Treehouse TeacherKen Alger
Treehouse TeacherShezan;
I'm not sure I understand your question. What are you attempting to get the display to show?
Ken