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
1130
votes
29 answers

How to add 30 minutes to a JavaScript Date object?

I'd like to get a Date object which is 30 minutes later than another Date object. How do I do it with JavaScript?
Morgan Cheng
  • 73,950
  • 66
  • 171
  • 230
1117
votes
17 answers

How do I use PHP to get the current year?

I want to put a copyright notice in the footer of a web site, but I think it's incredibly tacky for the year to be outdated. How would I make the year update automatically with PHP
JD Graffam
  • 11,275
  • 2
  • 18
  • 6
1113
votes
53 answers

Format JavaScript date as yyyy-mm-dd

I have a date with the format Sun May 11,2014. How can I convert it to 2014-05-11 using JavaScript? function taskDate(dateMilli) { var d = (new Date(dateMilli) + '').split(' '); d[2] = d[2] + ','; return [d[0], d[1], d[2],…
user3625547
  • 11,159
  • 3
  • 12
  • 6
1053
votes
22 answers

Is there any way to change input type="date" format?

By default, the input type="date" shows date as YYYY-MM-DD. The question is, is it possible to force it's format to something like: DD-MM-YYYY?
Tural Ali
  • 22,202
  • 18
  • 80
  • 129
1004
votes
17 answers

Java string to date conversion

What is the best way to convert a String in the format 'January 2, 2010' to a Date in Java? Ultimately, I want to break out the month, the day, and the year as integers so that I can use Date date = new…
littleK
  • 19,521
  • 30
  • 128
  • 188
997
votes
41 answers

Get month name from Date

How can I generate the name of the month (e.g: Oct/October) from this date object in JavaScript? var objDate = new Date("10/11/2009");
Shyju
  • 214,206
  • 104
  • 411
  • 497
955
votes
14 answers

Convert date to datetime in Python

Is there a built-in method for converting a date to a datetime in Python, for example getting the datetime for the midnight of the given date? The opposite conversion is easy: datetime has a .date() method. Do I really have to manually call…
EMP
  • 59,148
  • 53
  • 164
  • 220
931
votes
35 answers

Parsing a string to a date in JavaScript

How can I convert a string to a Date object in JavaScript? var st = "date in some format" var dt = new Date(); var dt_st = // st in Date format, same as dt.
jslearner
  • 21,331
  • 18
  • 37
  • 35
897
votes
37 answers

How to subtract days from a plain Date?

Is there an easy way of taking a olain JavaScript Date (e.g. today) and going back X days? So, for example, if I want to calculate the date 5 days before today.
jonhobbs
  • 26,684
  • 35
  • 115
  • 170
890
votes
31 answers

How do I get the day of week given a date?

I want to find out the following: given a date (datetime object), what is the corresponding day of the week? For instance, Sunday is the first day, Monday: second day.. and so on And then if the input is something like today's date. Example >>>…
frazman
  • 32,081
  • 75
  • 184
  • 269
878
votes
44 answers

Get the last day of the month

Is there a way using Python's standard library to easily determine (i.e. one function call) the last day of a given month? If the standard library doesn't support that, does the dateutil package support this?
Cristian
  • 42,563
  • 25
  • 88
  • 99
866
votes
28 answers

How to check whether an object is a date?

I have an annoying bug in on a webpage: date.GetMonth() is not a function So, I suppose that I am doing something wrong. The variable date is not an object of type Date. How can I check for a datatype in Javascript? I tried to add a if (date), but…
Martin
  • 39,309
  • 62
  • 192
  • 278
833
votes
5 answers

Get difference between 2 dates in JavaScript?

How do I get the difference between 2 dates in full days (I don't want any fractions of a day) var date1 = new Date('7/11/2010'); var date2 = new Date('12/12/2010'); var diffDays = date2.getDate() - date1.getDate(); alert(diffDays) I tried the…
chobo2
  • 83,322
  • 195
  • 530
  • 832
831
votes
35 answers

How to convert a Date to UTC?

Suppose a user of your website enters a date range. 2009-1-1 to 2009-1-3 You need to send this date to a server for some processing, but the server expects all dates and times to be in UTC. Now suppose the user is in Alaska. Since they are in a…
dthrasher
  • 40,656
  • 34
  • 113
  • 139
812
votes
25 answers

How to print a date in a regular format?

This is my code: import datetime today = datetime.date.today() print(today) This prints: 2008-11-22 which is exactly what I want. But, I have a list I'm appending this to and then suddenly everything goes "wonky". Here is the code: import…
NomadAlien
  • 9,090
  • 6
  • 25
  • 22