Questions tagged [datetime]

A DateTime object in many programming languages describes a date and a time of day. It can express either an instant in time or a position on a calendar, depending on the context in which it is used and the specific implementation. This tag can be used for all date and time related issues.

A DateTime object in many programming languages describes a date and a time of day. It can express either an instant in time or a position on a calendar, depending on the context in which it is used and the specific implementation.

  • In , os.date and os.time are provided as part of lua's standard library for working with date and time.

  • In the data types TIMESTAMP [WITHOUT TIME ZONE] and TIMESTAMP WITH TIME ZONE are collectively referred to as timestamps. (And the data types DATE, TIME, and TIMESTAMP are collectively referred to as datetime types.)

  • In , datetime is a type that represents a date and time of day. It carries no time zone context, so it is a position on a calendar, not a moment in time.

  • In , DATETIME values represent a date and time of day. They carry no time zone context, so they are positions on a calendar, not a moment in time. TIMESTAMP values represent a moment in time, and are based on UNIX time. When MySQL stores TIMESTAMPs, it converts them from the current connection's time zone setting to UTC. When displaying them it converts them back.

  • In , DateTime is a structure that is typically expressed as a date and time of day. It represents either an instant in time, or a position on a calendar. The precise meaning is dependent on the value of its Kind property.

  • In , Instant is a class that represents an instant in time. Before Java 8 was a popular library, DateTime is a class which represents an instant in time, with reference to a particular time zone.

  • In , datetime is an object which represents a date and time of day. The precise meaning is dependent on the value of its tzinfo property. It is also the name of the module that provides date, time, datetime, and related objects.

  • In the DateTime class is a representation of a instant in time, with reference to a particular time zone.

  • In , the time and date manipulation library datetime-fortran can be used.

  • In , a Date instance represents a single moment in time. Date objects are based on a time value that is the number of milliseconds since 1 January, 1970 UTC. That is, they are UNIX time values in milliseconds.

  • In , the classes "POSIXlt" and "POSIXct" represent calendar dates and times.Subtraction of two date-time objects is equivalent to using difftime. Class "POSIXct" represents the (signed) number of seconds since the beginning of 1970 (in the UTC time zone) as a numeric vector. Class "POSIXlt" is a named list of vectors representing sec, min, hour et al

  • In , Microsoft Excel for Windows uses the 1900 date system, by default. Which means the first date is January 1, 1900. a Date and Time function can be used to manipulate the year/date and time/hour/minutes values. The date/time in Excel is stored as a number. Where the decimal part range from 0.0 to 0.99988426 represent 0:00:00 (12:00:00 AM) to 23:59:59 (11:59:59 P.M.), and the integer part range from 0 to 9999 represent days. But Excel's date representation is slightly off in the first two months of calendar year 1900.


Helpful articles

70365 questions
350
votes
17 answers

How to truncate the time on a datetime object?

What is a classy way to way truncate a python datetime object? In this particular case, to the day. So basically setting hour, minute, seconds, and microseconds to 0. I would like the output to also be a datetime object, not a string.
Kyle Brandt
  • 26,938
  • 37
  • 124
  • 165
350
votes
14 answers

How can I convert seconds into (Hour:Minutes:Seconds:Milliseconds) time?

How can I convert seconds into (Hour:Minutes:Seconds:Milliseconds) time? Let's say I have 80 seconds; are there any specialized classes/techniques in .NET that would allow me to convert those 80 seconds into (00h:00m:00s:00ms) format like…
John Gates
346
votes
14 answers

Convert UTC/GMT time to local time

We are developing a C# application for a web-service client. This will run on Windows XP PC's. One of the fields returned by the web service is a DateTime field. The server returns a field in GMT format i.e. with a "Z" at the end. However, we found…
rbrayb
  • 46,440
  • 34
  • 114
  • 174
344
votes
5 answers

In Python, how do you convert seconds since epoch to a `datetime` object?

The time module can be initialized using seconds since epoch: >>> import time >>> t1=time.gmtime(1284286794) >>> t1 time.struct_time(tm_year=2010, tm_mon=9, tm_mday=12, tm_hour=10, tm_min=19, tm_sec=54, tm_wday=6, tm_yday=255,…
Adam Matan
  • 128,757
  • 147
  • 397
  • 562
339
votes
16 answers

Filtering Pandas DataFrames on dates

I have a Pandas DataFrame with a 'date' column. Now I need to filter out all rows in the DataFrame that have dates outside of the next two months. Essentially, I only need to retain the rows that are within the next two months. What is the best way…
AMM
  • 17,130
  • 24
  • 65
  • 77
337
votes
3 answers

How do you convert a time.struct_time object into a datetime object?

How do you convert a Python time.struct_time object into a datetime.datetime object? I have a library that provides the first one and a second library that wants the second one.
static_rtti
  • 53,760
  • 47
  • 136
  • 192
337
votes
14 answers

Can't compare naive and aware datetime.now() <= challenge.datetime_end

I am trying to compare the current date and time with dates and times specified in models using comparison operators: if challenge.datetime_start <= datetime.now() <= challenge.datetime_end: The script errors out with: TypeError: can't compare…
sccrthlt
  • 3,974
  • 5
  • 20
  • 24
334
votes
24 answers

How to convert DateTime to VarChar

I need to convert a value which is in a DateTime variable into a varchar variable formatted as yyyy-mm-dd format (without time part). How do I do that?
Ali
  • 5,499
  • 7
  • 25
  • 28
330
votes
29 answers

How to get the current time as datetime

Just started with the playground. I'm trying to create a simple app. I've created a date object like this: var date = NSDate() How can I get the current hour? In other languages I can do something like this: var hour = date.hour But I can't find…
JOSEFtw
  • 9,781
  • 9
  • 49
  • 67
329
votes
17 answers

Convert string date to timestamp in Python

How to convert a string in the format "%d/%m/%Y" to timestamp? "01/12/2011" -> 1322697600
Shankar Cabus
  • 9,302
  • 7
  • 33
  • 43
326
votes
14 answers

How to convert a UTC datetime to a local datetime using only standard library?

I have a python datetime instance that was created using datetime.utcnow() and persisted in database. For display, I would like to convert the datetime instance retrieved from the database to local datetime using the default local timezone (i.e., as…
Nitro Zark
  • 3,377
  • 2
  • 15
  • 6
326
votes
12 answers

How to print pandas DataFrame without index

I want to print the whole dataframe, but I don't want to print the index Besides, one column is datetime type, I just want to print time, not date. The dataframe looks like: User ID Enter Time Activity Number 0 123 2014-07-08…
lserlohn
  • 5,878
  • 10
  • 34
  • 52
325
votes
16 answers

How do I output an ISO 8601 formatted string in JavaScript?

I have a Date object. How do I render the title portion of the following snippet? A couple days ago I have the "relative time in words" portion from another library. I've tried the following: function…
James A. Rosen
  • 64,193
  • 61
  • 179
  • 261
324
votes
5 answers

Convert timedelta to total seconds

I have a time difference import time import datetime time1 = datetime.datetime.fromtimestamp(time.mktime(time.gmtime())) ... time2 = datetime.datetime.fromtimestamp(time.mktime(time.gmtime())) diff = time2 - time1 Now, how do I find the total…
ripper234
  • 222,824
  • 274
  • 634
  • 905
322
votes
14 answers

How can I truncate a datetime in SQL Server?

What's the best way to truncate a datetime value (as to remove hours minutes and seconds) in SQL Server? For example: declare @SomeDate datetime = '2009-05-28 16:30:22' select trunc_date(@SomeDate) ----------------------- 2009-05-28 00:00:00.000
Julio César
  • 12,790
  • 10
  • 38
  • 45