why datetime.now() and constructed datetime using all fields(like year,month...) of now has big timedelta?

why datetime.now() and constructed datetime using all fields(like year,month...) of now has big timedelta?

Content Index :

why datetime.now() and constructed datetime using all fields(like year,month...) of now has big timedelta?
Tag : python , By : ap.
Date : January 11 2021, 03:34 PM

This might help you That output is correct. It's telling you that, in order to make testTime equal to now, you'd need to subtract one day from testTime (that's the -1 day), then add back 23 hours, 59 minutes, 59 seconds, and 106000 microseconds. Effectively, that's saying "testTime is 894000 microseconds before now", which is correct; you truncated off the microseconds, makingtestTime ever-so-slightly earlier than now.
Are you sure you didn't flip your operands? print(now - testTime) would output 0:00:00.894000 which is probably the output you were looking for.

No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

Symfony - search table by month, year for datetime fields

Tag : development , By : user119605
Date : March 29 2020, 07:55 AM
Hope this helps Why dont you try to create 2 date and check if that date is between them, for example (2010-01-01 >= $date && 2010-01-31 <= $date ). If so, then your in range and all coincidences will appear.
If you absolutely have to check for month and year i recommend using functions like YEAR(date) = $yourDate and Month(date) = $yourMonth, this functions should go along with a CUSTOM criteria and could look like:
$criterias->addCriteria(TablePeer::DATE_ATTRIBUTE,"YEAR(". TablePeer::DATE_ATTRIBUTE .") = $year",Criteria::CUSTOM);
$criterias->addCriteria(TablePeer::DATE_ATTRIBUTE,"MONTH(". TablePeer::DATE_ATTRIBUTE .") = $month",Criteria::CUSTOM);

Counting year and month entries from datetime fields

Tag : mysql , By : user169463
Date : March 29 2020, 07:55 AM
Hope this helps You will need two separate queries, one for subscriptions and other for unsubscriptions.
SELECT COUNT(*), YEAR(fDateConfirmed), MONTH(fDateConfirmed) FROM tSubscriber GROUP BY YEAR(fDateConfirmed), MONTH(fDateConfirmed)
SELECT COUNT(*), YEAR(fDateUnsubscribed), MONTH(fDateUnsubscribe ) FROM tSubscriber GROUP BY YEAR(fDateUnsubscribed), MONTH(fDateUnsubscribed)

Wanted: DateTime.TryNew(year, month, day) or DateTime.IsValidDate(year, month, day)

Tag : chash , By : joshski
Date : March 29 2020, 07:55 AM
seems to work fine There is not a static function IsValidDate() so you have to write it by yourself, first naive implementation may be:
public static bool IsValidDate(int year, int month, int day)
    if (year < DateTime.MinValue.Year || year > DateTime.MaxValue.Year)
        return false;

    if (month < 1 || month > 12)
        return false;

    return day > 0 && day <= DateTime.DaysInMonth(year, month);
public static DateTime? TryNew(int year,
                               int month,
                               int day,
                               Calendar calendar)
    if (calendar == null)
        calendar = new GregorianCalendar();

    if (year < calendar.MinSupportedDateTime.Year)
        return null;

    if (year > calendar.MaxSupportedDateTime.Year)
        return null;

    // Note that even with this check we can't assert this is a valid
    // month because one year may be "shared" for two eras moreover here
    // we're assuming current era.
    if (month < 1 || month > calendar.GetMonthsInYear(year))
        return null;

    if (day <= 0 || day > DateTime.DaysInMonth(year, month))
        return null;

    // Now, probably, date is valid but there may still be issues
    // about era and missing days because of calendar changes.
    // For all this checks we rely on DateTime implementation.        
        return new DateTime(year, month, day, calendar);
    catch (ArgumentOutOfRangeException)
        return null;
return TryNew(year, month, day) ?? DateTime.MinValue;

Why does datetime.datetime.now() - datetime.datetime.now() equal to datetime.timedelta(-1, 86399, 999974)?

Tag : python , By : Tim Tyrrell
Date : March 29 2020, 07:55 AM
To fix the issue you can do Consider the following snippet: , See the datetime.timedelta documenation:
>>> from datetime import timedelta
>>> d = timedelta(microseconds=-1)
>>> (d.days, d.seconds, d.microseconds) (-1, 86399, 999999)
>>> import datetime
>>> td = datetime.datetime.now() - datetime.datetime.now()
>>> print(td)
-1 day, 23:59:59.999988
>>> td
datetime.timedelta(-1, 86399, 999988)
>>> td.days
>>> td.seconds
>>> td.microseconds
>>> (24 * 60 * 60)  # 1 day in seconds
>>> (24 * 60 * 60) - td.seconds
>>> 1000000 - td.microseconds

Django - Need datetime fields that can handle only year, or year and month values

Tag : python , By : T11M
Date : March 29 2020, 07:55 AM
Related Posts Related QUESTIONS :
  • Detect if user has clicked the 'maximized' button
  • Does flask_login automatically set the "next" argument?
  • Indents in python 3
  • How to create a pool of threads
  • Pandas giving IndexError on one dataframe but not on another similar dataframe
  • Django Rest Framework - Testing client.login doesn't login user, ret anonymous user
  • Running dag without dag file in airflow
  • Filling across a specified dimension of a numpy array
  • Python populating dataframe in pandas from text files
  • How to interpolate a single ("non-piecewise") cubic spline from a set of data points?
  • Divide 2 integers (leetcode 29) - recursion issue
  • Can someone explain why do I get this output in Python?
  • How do I scrape pdf and html from search results without obvious url
  • Is there a way to automatically make a "collage" of plots with matplotlib?
  • How to combine multiple rows in pandas with shared column values
  • How do I get LOAD_CLASSDEREF instruction after dis.dis?
  • Django - How to add items to Bootstrap dropdown?
  • Linear Regression - Does the below implementation of ridge regression finding coefficient term using gradient method is
  • How to drop all rows in pandas dataframe with negative values?
  • Most Efficient Way to Find Closest Date Between 2 Dataframes
  • Execution error when Passing arguments to a python script using os.system. The script takes sys.argv arguments
  • Looping through a function
  • Create a plot for each unique ID
  • a thread python with 'while' got another thread never start
  • Solution from SciPy solve_ivp contains oscillations for a system of first-order ODEs
  • trigger python events driven by selenium controlled browser
  • Passing line-edits to a contextmanager to set validators
  • Python: globals().items() iterations try to change a dict
  • Is it possible to specify starting values for each parameter (instead of bounds) for scipy's differential evolution?
  • MySQL multiple table UPDATE query using sqlalchemy core?
  • find if a semantic version is superset of of another version python
  • Type checking against dynamically created objects
  • Struggling with simple reverse function
  • Is there a function for finding the midpoint of n points on sklearn.neighbors.NearestNeighbors?
  • How to set max number of tweets to fetch
  • PYTHON 3.7.4 NOT USING SQLITE 3.29.0
  • How to replace Nan value with zeros in a numpy array?
  • How to speed up calculating variance among sparse matrix
  • cupy code is not fast enough compared with numpy
  • How to count frequency of select values in Python pandas dataframe
  • Scrape Span Text from Google
  • Python watchdog, watch a directory and rename file on event.modification
  • Filtering rows in DataFrame with dependent conditions
  • How to check if a character is a not a part of number or URL in string?
  • Compare corresponding elements of a list
  • Python misinterprets 3 character string as UTF-8 continuation byte
  • Merge two columns in Pandas
  • Side Effect error in Python in an online compiler
  • How to convert a navigation list with depth levels to a parent-child flat list?
  • Retrieving values from a paired key dictionary in Python
  • How to test the current text of a Tkinter text box widget before inserting new text after user clicks on a button?
  • computing the Cumulative Sum, where Sum can be reset by a condition
  • Where do you specify your API key when making a request with the Google API python library?
  • Pandas DataFrame, computing the Time Difference between one row and other row which satisfies a condition
  • Discord.py bot not reading other bot's messages
  • How do I write a Django query that finds words in a Postgres column?
  • Download S3 File Using Boto3
  • Retrieve status of model training after closing notebook
  • If Current Date is in Column Then Show Row
  • How do I stay in a for loop's element until a condition is met?
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com