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
802
votes
16 answers

How to get the current time in YYYY-MM-DD HH:MI:Sec.Millisecond format in Java?

The code below gives me the current time. But it does not tell anything about milliseconds. public static String getCurrentTimeStamp() { SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//dd/MM/yyyy Date now = new…
Sunil Kumar Sahoo
  • 53,011
  • 55
  • 178
  • 243
798
votes
31 answers

Converting ISO 8601-compliant String to java.util.Date

I am trying to convert an ISO 8601 formatted String to a java.util.Date. I found the pattern yyyy-MM-dd'T'HH:mm:ssZ to be ISO8601-compliant if used with a Locale (compare sample). However, using the java.text.SimpleDateFormat, I cannot convert the…
Ice09
  • 8,951
  • 4
  • 23
  • 25
787
votes
18 answers

MySQL Query GROUP BY day / month / year

Is it possible to make a simple query to count how many records I have in a determined period of time like a year, month, or day, having a TIMESTAMP field, like: SELECT COUNT(id) FROM stats WHERE record_date.YEAR = 2009 GROUP BY…
Fernando Barrocal
  • 12,584
  • 9
  • 44
  • 51
751
votes
16 answers

How to calculate number of days between two given dates

If I have two dates (ex. '8/18/2008' and '9/26/2008'), what is the best way to get the number of days between these two dates?
Ray
  • 187,153
  • 97
  • 222
  • 204
746
votes
25 answers

Batch file to delete files older than N days

I am looking for a way to delete all files older than 7 days in a batch file. I've searched around the web, and found some examples with hundreds of lines of code, and others that required installing extra command line utilities to accomplish the…
Kibbee
  • 65,369
  • 27
  • 142
  • 182
661
votes
32 answers

How can I increment a date by one day in Java?

I'm working with a date in this format: yyyy-mm-dd. How can I increment this date by one day?
user48094
  • 10,481
  • 12
  • 36
  • 30
656
votes
12 answers

What is this date format? 2011-08-12T20:17:46.384Z

I have the following date: 2011-08-12T20:17:46.384Z. What format is this? I'm trying to parse it with Java 1.4 via DateFormat.getDateInstance().parse(dateStr) and I'm getting java.text.ParseException: Unparseable date:…
Sarah Vessels
  • 30,930
  • 33
  • 155
  • 222
651
votes
10 answers

java.util.Date to XMLGregorianCalendar

Isn't there a convenient way of getting from a java.util.Date to a XMLGregorianCalendar?
mac
  • 9,885
  • 4
  • 36
  • 51
651
votes
35 answers

Getting current date and time in JavaScript

I have a script that prints the current date and time in JavaScript, but the DATE is always wrong. Here is the code: var currentdate = new Date(); var datetime = "Last Sync: " + currentdate.getDay() + "/" + currentdate.getMonth() + "/" +…
Ricardo
  • 11,609
  • 8
  • 27
  • 39
630
votes
18 answers

Adding days to a date in Python

I have a date "10/10/11(m-d-y)" and I want to add 5 days to it using a Python script. Please consider a general solution that works on the month ends also. I am using following code: import re from datetime import datetime StartDate =…
MuraliKrishna
  • 6,577
  • 3
  • 18
  • 11
628
votes
26 answers

How to get current time and date in C++?

Is there a cross-platform way to get the current date and time in C++?
Max Frai
  • 61,946
  • 78
  • 197
  • 306
610
votes
33 answers

Javascript add leading zeroes to date

I've created this script to calculate the date for 10 days in advance in the format of dd/mm/yyyy: var MyDate = new Date(); var MyDateString = new Date(); MyDate.setDate(MyDate.getDate()+10); MyDateString = MyDate.getDate() + '/' +…
Julian Coates
  • 6,129
  • 3
  • 16
  • 5
595
votes
23 answers

Best approach to remove time part of datetime in SQL Server

Which method provides the best performance when removing the time portion from a datetime field in SQL Server? a) select DATEADD(dd, DATEDIFF(dd, 0, getdate()), 0) or b) select cast(convert(char(11), getdate(), 113) as datetime) The second method…
Stephen Perelson
  • 6,613
  • 3
  • 21
  • 15
594
votes
29 answers

jQuery UI DatePicker - Change Date Format

I am using the UI DatePicker from jQuery UI as the stand alone picker. I have this code:
And the following JS: $('#datepicker').datepicker(); When I try to return the value with this code: var date =…
tarnfeld
  • 25,992
  • 41
  • 111
  • 146
584
votes
23 answers

Creating a range of dates in Python

I want to create a list of dates, starting with today, and going back an arbitrary number of days, say, in my example 100 days. Is there a better way to do it than this? import datetime a = datetime.datetime.today() numdays = 100 dateList = [] for…
Thomas Browne
  • 23,824
  • 32
  • 78
  • 121