Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7432713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:30:07+00:00 2026-05-29T09:30:07+00:00

I need to get the following values Today = 6th Feb time 1 =

  • 0

I need to get the following values

Today = 6th Feb
time 1 = 5th Feb 0000 hrs
time 2 = 6th Feb 0000 hrs.

So I have 24 hours in epoch time. The reference is today but not now()

So far I have this.

yesterday = datetime.date.today() - datetime.timedelta(days=1)
epoch_yesterday =  time.mktime(yesterday.timetuple())
epoch_today = time.mktime(datetime.date.today().timetuple())

Both epoch_ values are actually returning seconds from now() like 1600 hrs (depends on when I run the script) not from 0000/2400 hrs. I understand it would be better to get yesterdays epoch time and then ad 24 hours to it to get the end date. But I need to get the first part right 🙂 , maybe I need sleep?

p.s. Sorry code styling isn’t working, SO won’t let me post with code styling and was very frustrating to get SO to post this.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T09:30:08+00:00Added an answer on May 29, 2026 at 9:30 am

    The simpler way might be to construct the date explicitly as so:

    now = datetime.now()
    previous_midnight = datetime.datetime( now.year, now.month, now.day )
    

    That gets you the timestamp for the just passed midnight. As you already know time.mktime will get you your the epoch value. Just add or subtract 24 * 60 * 60 to get the previous or next midnight from there.

    Oh! And be aware that the epochal value will be seconds from midnight 1970, Jan 1st UTC. If you need seconds from midnight in your timezone, remember to adjust accordingly!

    Update: test code, executed from the shell at just before 1 pm, PST:

    >>> from datetime import datetime
    >>> import time
    >>> time_now = datetime.now()
    >>> time_at_start_of_today_local = datetime( n.year, n.month, n.day )
    >>> epochal_time_now = time.mktime( time_now.timetuple() )
    >>> epochal_time_at_start_of_today_local = time.mktime( time_at_start_of_today.timetuple() )
    >>> hours_since_start_of_day_today = (epochal_time_at_start_of_today_local - epochal_time_now) / 60 / 60
    12.975833333333332
    

    Note: time_at_start_of_today_local is the number of seconds between 1970 Jan 1st, midnight, and the start of the current day in your timezone. If you want the number of seconds to the start of the current day in UTC, then subtract your time zone from time_at_start_of_today_local:

    >>> time_at_start_of_today_utc = time_at_start_of_today_local - time.timezone
    

    Be aware that you get into odd territory here, specifically who’s day do you care about? If it’s currently Tuesday in your timezone, but still Monday in UTC, which midnight do you consider today’s midnight for your purposes?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following HTML and I need to get the first div parent
I'm facing a hard time to get the following query: Let's say I have
I need to get the following values out of the xml below. I've snipped
I need to implement a prioritised collection. Assuming we have the following three values
I need to get my dates to be into the following format: 12/3/2011 for
I'm stuck with the following. I'm programming a game and I need to get
I need to do the following and i was wondering if i could get
Wondering if I could get some advice and direction on this following requirement: Need
I need get all items these have no categories int? categoryId = null; var
I have two tables with a weak relation. I need get a text value

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.