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
576
votes
34 answers

How can I get the current date and time in UTC or GMT in Java?

When I create a new Date object, it is initialized to the current time but in the local timezone. How can I get the current date and time in GMT?
Behrang
  • 9,789
  • 6
  • 24
  • 19
560
votes
44 answers

How to set input type date's default value to today?

Given an input element: Is there any way to set the default value of the date field to today's date?
Ian Brown
  • 5,601
  • 3
  • 15
  • 4
559
votes
18 answers

Convert a date format in PHP

I am trying to convert a date from yyyy-mm-dd to dd-mm-yyyy (but not in SQL); however I don't know how the date function requires a timestamp, and I can't get a timestamp from this string. How is this possible?
matthy
  • 8,144
  • 10
  • 38
  • 47
556
votes
7 answers

java.util.Date vs java.sql.Date

java.util.Date vs java.sql.Date: when to use which and why?
flybywire
  • 261,858
  • 191
  • 397
  • 503
554
votes
20 answers

Incrementing a date in JavaScript

I need to increment a date value by one day in JavaScript. For example, I have a date value 2010-09-11 and I need to store the date of the next day in a JavaScript variable. How can I increment a date by a day?
Santanu
  • 7,764
  • 7
  • 26
  • 24
552
votes
42 answers

How to calculate number of days between two dates?

For example, given two dates in input boxes: How do I get the number of days between two…
Michael Haren
  • 105,752
  • 40
  • 168
  • 205
544
votes
17 answers

Get hours difference between two dates in Moment Js

I'm able to get the difference between two dates using MomentJs as follows: moment(end.diff(startTime)).format("m[m] s[s]") However, I also want to display the hour when applicable (only when >= 60 minutes have passed). However, when I try to…
Dani
  • 5,828
  • 2
  • 17
  • 21
538
votes
53 answers

Get String in YYYYMMDD format from JS date object?

I'm trying to use JS to turn a date object into a string in YYYYMMDD format. Is there an easier way than concatenating Date.getYear(), Date.getMonth(), and Date.getDay()?
IVR Avenger
  • 15,090
  • 13
  • 46
  • 57
537
votes
25 answers

Iterating through a range of dates in Python

I have the following code to do this, but how can I do it better? Right now I think it's better than nested loops, but it starts to get Perl-one-linerish when you have a generator in a list comprehension. day_count = (end_date - start_date).days +…
ShawnMilo
  • 5,896
  • 3
  • 19
  • 15
526
votes
28 answers

Comparing date part only without comparing time in JavaScript

What is wrong with the code below? Maybe it would be simpler to just compare date and not time. I am not sure how to do this either, and I searched, but I couldn't find my exact problem. BTW, when I display the two dates in an alert, they show as…
moleculezz
  • 7,513
  • 4
  • 25
  • 25
514
votes
17 answers

How to convert java.util.Date to java.sql.Date?

I am trying to use a java.util.Date as input and then creating a query with it - so I need a java.sql.Date. I was surprised to find that it couldn't do the conversion implicitly or explicitly - but I don't even know how I would do this, as the…
David Ackerman
  • 12,649
  • 6
  • 24
  • 19
514
votes
23 answers

Change date format in a Java string

I've a String representing a date. String date_s = "2011-01-18 00:00:00.0"; I'd like to convert it to a Date and output it in YYYY-MM-DD format. 2011-01-18 How can I achieve this? Okay, based on the answers I retrieved below, here's something…
amit4444
  • 5,209
  • 3
  • 15
  • 3
498
votes
46 answers

Calculating the difference between two Java date instances

I'm using Java's java.util.Date class in Scala and want to compare a Date object and the current time. I know I can calculate the delta by using getTime(): (new java.util.Date()).getTime() - oldDate.getTime() However, this just leaves me with a…
pr1001
  • 21,727
  • 17
  • 79
  • 125
484
votes
30 answers

How to find the last day of the month from date?

How can I get the last day of the month in PHP? Given: $a_date = "2009-11-23" I want 2009-11-30; and given $a_date = "2009-12-23" I want 2009-12-31.
Mithun Sreedharan
  • 49,883
  • 70
  • 181
  • 236
483
votes
33 answers

How do you display JavaScript datetime in 12 hour AM/PM format?

How do you display a JavaScript datetime object in the 12 hour format (AM/PM)?
bbrame
  • 18,031
  • 10
  • 35
  • 52