Questions tagged [date]

A date is a reference to a particular day represented within a calendar system, and consists of year, month and day. Use for questions about creating, manipulating and storing date information. Use with any relevant language tags.

A date is an ambiguous interval in time, which usually refers to a day, month, and year in a particular calendar system.

A date by itself (such as Jan 1 2014) does not refer to a specific moment in time.

  • It does not have a time of day, so it refers to a whole calendar date.
  • It does not specify a time zone, so it could be interpreted differently by each viewer.

Related concepts such as "today", "yesterday", and "tomorrow", or any individual day of the week such as "Monday" or "Tuesday", also have the same qualities. They are loose terms that require a time zone in order to lock in to a specific range of time.

In some programming languages, such as , the Date type actually represents a date and time of day and is therefore misnamed.

The most recognized calendar is the Gregorian calendar, but there are other known calendars such as the Hebrew or the Hijri (Muslim) calendar. Since both start at a different date from the Gregorian calendar's date, the dates in these calendars are different. When one intends to implement an international application or website, the different calendars might be good to be taken into account.

See also: , , and

76185 questions
483
votes
9 answers

Python date string to date object

How do I convert a string to a date object in python? The string would be: "24052010" (corresponding to the format: "%d%m%Y") I don't want a datetime.datetime object, but rather a datetime.date.
elif
  • 5,427
  • 3
  • 28
  • 28
482
votes
19 answers

How do I get a value of datetime.today() in Python that is "timezone aware"?

I am trying to subtract one date value from the value of datetime.datetime.today() to calculate how long ago something was. But it complains: TypeError: can't subtract offset-naive and offset-aware datetimes The return value from…
mindthief
  • 12,755
  • 14
  • 57
  • 61
466
votes
7 answers

Convert Pandas Column to DateTime

I have one field in a pandas DataFrame that was imported as string format. It should be a datetime variable. How do I convert it to a datetime column, and then filter based on date? Example: raw_data = pd.DataFrame({'Mycol':…
Chris
  • 12,900
  • 12
  • 43
  • 65
461
votes
3 answers

In Ruby on Rails, what's the difference between DateTime, Timestamp, Time and Date?

In my experience, getting dates/times right when programming is always fraught with danger and difficulity. Ruby and Rails have always eluded me on this one, if only due to the overwhelming number of options; I never have any idea which I should…
Nick
  • 4,765
  • 3
  • 17
  • 9
456
votes
17 answers

Convert java.util.Date to String

I want to convert a java.util.Date object to a String in Java. The format is 2010-05-30 22:15:52
novicePrgrmr
  • 18,647
  • 31
  • 81
  • 103
446
votes
11 answers

How to compare dates in Java?

How do I compare dates in between in Java? Example: date1 is 22-02-2010 date2 is 07-04-2010 today date3 is 25-12-2010 date3 is always greater than date1 and date2 is always today. How do I verify if today's date is in between date1 and date 3?
ant
  • 22,634
  • 36
  • 132
  • 182
432
votes
20 answers

Calculate the date yesterday in JavaScript

How can I calculate yesterday as a date in JavaScript?
Omega
  • 8,640
  • 9
  • 30
  • 29
421
votes
4 answers

How do I express a date type in TypeScript?

How do I express dates in TypeScript? Dates aren't a TypeScript type, so do I use any or object? Seems like there would be a "right" way to do: let myDate: any = new Date(); I couldn't find much on Google, despite it being such a simple question.
VSO
  • 11,546
  • 25
  • 99
  • 187
416
votes
45 answers

Difference in months between two dates

How to calculate the difference in months between two dates in C#? Is there is equivalent of VB's DateDiff() method in C#. I need to find difference in months between two dates that are years apart. The documentation says that I can use TimeSpan…
Rauf
  • 12,326
  • 20
  • 77
  • 126
414
votes
33 answers

Is the Javascript date object always one day off?

In my Java Script app I have the date stored in a format like so: 2011-09-24 Now when I try using the above value to create a new Date object (so I can retrieve the date in a different format), the date always comes back one day off. See below: var…
levi
  • 23,693
  • 18
  • 59
  • 73
408
votes
47 answers

JavaScript seconds to time string with format hh:mm:ss

I want to convert a duration of time, i.e., number of seconds to colon-separated time string (hh:mm:ss) I found some useful answers here but they all talk about converting to x hours and x minutes format. So is there a tiny snippet that does this in…
medk
  • 9,233
  • 18
  • 57
  • 79
408
votes
2 answers

Get first and last date of current month with JavaScript or jQuery

As title says, I'm stuck on finding a way to get the first and last date of the current month with JavaScript or jQuery, and format it as: For example, for November it should be : var firstdate = '11/01/2012'; var lastdate = '11/30/2012';
Moozy
  • 4,735
  • 3
  • 18
  • 18
404
votes
25 answers

Calculate last day of month

If you provide 0 as the dayValue in Date.setFullYear you get the last day of the previous month: d = new Date(); d.setFullYear(2008, 11, 0); // Sun Nov 30 2008 There is reference to this behaviour at mozilla. Is this a reliable cross-browser…
Ken
  • 77,016
  • 30
  • 84
  • 101
403
votes
11 answers

Why does Date.parse give incorrect results?

Case One: new Date(Date.parse("Jul 8, 2005")); Output: Fri Jul 08 2005 00:00:00 GMT-0700 (PST) Case Two: new Date(Date.parse("2005-07-08")); Output: Thu Jul 07 2005 17:00:00 GMT-0700 (PST) Why is the second parse incorrect?
user121196
  • 30,032
  • 57
  • 148
  • 198
397
votes
17 answers

Convert UTC Epoch to local date

I have been fighting with this for a bit now. I’m trying to convert epoch to a date object. The epoch is sent to me in UTC. Whenever you pass new Date() an epoch, it assumes it’s local epoch. I tried creating a UTC object, then using setTime() to…
Shane Reustle
  • 8,633
  • 8
  • 40
  • 51