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.

Filter by
Sorted by
Tagged with
372 votes
17 answers
638k views

Convert one date format into another in PHP

Is there a simple way to convert one date format into another date format in PHP? I have this: $old_date = date('y-m-d-h-i-s'); // works $middle = strtotime($old_date); // ...
  • 29.6k
394 votes
11 answers
499k views

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 ...
  • 29.3k
3229 votes
65 answers
5.9m views

How do I format a date in JavaScript?

How do I format a Date object to a string?
  • 181k
1488 votes
39 answers
1.5m views

Where can I find documentation on formatting a date in JavaScript?

I noticed that JavaScript's new Date() function is very smart in accepting dates in several formats. Xmas95 = new Date("25 Dec, 1995 23:15:00") Xmas95 = new Date("2009 06 12,12:52:39") Xmas95 = new ...
988 votes
17 answers
2.3m views

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 = ...
  • 19.1k
2611 votes
42 answers
3.1m views

Compare two dates with JavaScript

Can someone suggest a way to compare the values of two dates greater than, less than, and not in the past using JavaScript? The values will be coming from text boxes.
  • 37.7k
1259 votes
29 answers
1.3m views

Sort ArrayList of custom Objects by property

I read about sorting ArrayLists using a Comparator but in all of the examples people used compareTo which according to some research is a method for Strings. I wanted to sort an ArrayList of custom ...
  • 18k
881 votes
36 answers
2.6m views

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.
  • 20.3k
1566 votes
55 answers
1.9m views

How to add days to Date?

How to add days to current Date using JavaScript? Does JavaScript have a built in function like .NET's AddDay()?
  • 15.7k
491 votes
45 answers
752k views

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....
  • 21.4k
525 votes
41 answers
693k views

How to calculate number of days between two dates?

For example, given two dates in input boxes: <input id="first" value="1/1/2000"/> <input id="second" value="1/1/2001"/> <script> alert(...
773 votes
30 answers
802k views

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 ...
  • 8,691
505 votes
22 answers
1.6m views

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 ...
  • 5,119
793 votes
5 answers
1.2m views

Get difference between 2 dates in JavaScript? [duplicate]

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() - ...
  • 81.1k
997 votes
20 answers
1.9m views

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?
  • 21.3k
109 votes
8 answers
191k views

Converting year and month ("yyyy-mm" format) to a date?

I have a dataset that looks like this: Month count 2009-01 12 2009-02 310 2009-03 2379 2009-04 234 2009-05 14 2009-08 1 2009-09 34 2009-10 2386 I want to plot the data (months as x values ...
  • 10.3k
1532 votes
33 answers
2.2m views

Convert a Unix timestamp to time in JavaScript

I am storing time in a MySQL database as a Unix timestamp and that gets sent to some JavaScript code. How would I get just the time out of it? For example, in HH/MM/SS format.
  • 28.5k
540 votes
18 answers
2.0m views

Convert a date format in PHP [duplicate]

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 ...
  • 7,936
23 votes
3 answers
23k views

Left Outer Join doesn't return all rows from my left table?

I am trying to get the number of page opens on a per day basis using the following query. SELECT day.days, COUNT(*) as opens FROM day LEFT OUTER JOIN tracking ON day.days = DAY(FROM_UNIXTIME(...
  • 54.6k
433 votes
11 answers
1.1m views

How to compare dates in Java? [duplicate]

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 ...
  • 22.2k
646 votes
31 answers
1.1m views

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?
  • 10.2k
328 votes
21 answers
708k views

How to get time difference in minutes in PHP

How to calculate minute difference between two date-times in PHP?
2880 votes
61 answers
3.9m views

How do I get the current date in JavaScript?

How do I get the current date in JavaScript?
  • 37.5k
7413 votes
10 answers
772k views

Why is subtracting these two times (in 1927) giving a strange result?

If I run the following program, which parses two date strings referencing times 1 second apart and compares them: public static void main(String[] args) throws ParseException { SimpleDateFormat sf ...
  • 189k
35 votes
2 answers
29k views

What are valid Date Time Strings in JavaScript?

When using new Date or Date.parse in JavaScript, I cannot just pass arbitrary date formats. Depending on the format, I get a different date than I wanted to or even Invalid Date instead of a date ...
  • 40k
240 votes
13 answers
166k views

How can I parse / create a date time stamp formatted with fractional seconds UTC timezone (ISO 8601, RFC 3339) in Swift?

How to generate a date time stamp, using the format standards for ISO 8601 and RFC 3339? The goal is a string that looks like this: "2015-01-01T00:00:00.000Z" Format: year, month, day, as &...
2093 votes
45 answers
3.4m views

How to return only the Date from a SQL Server DateTime datatype

SELECT GETDATE() Returns: 2008-09-22 15:24:13.790 I want that date part without the time part: 2008-09-22 00:00:00.000 How can I get that?
  • 32.8k
195 votes
5 answers
456k views

How to parse a date? [duplicate]

I am trying to parse this date with SimpleDateFormat and it is not working: import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class Formaterclass { ...
  • 5,427
378 votes
45 answers
570k views

Calculate age given the birth date in the format YYYYMMDD

How can I calculate an age in years, given a birth date of format YYYYMMDD? Is it possible using the Date() function? I am looking for a better solution than the one I am using now: var dob = '...
  • 74.2k
733 votes
25 answers
1.3m views

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 ...
  • 64.7k
959 votes
48 answers
2.2m views

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] = ...
  • 9,619
218 votes
7 answers
49k views

How to prevent ifelse() from turning Date objects into numeric objects

I am using the function ifelse() to manipulate a date vector. I expected the result to be of class Date, and was surprised to get a numeric vector instead. Here is an example: dates <- as.Date(c('...
  • 29.1k
1953 votes
51 answers
1.3m views

Detecting an "invalid date" Date instance in JavaScript

I'd like to tell the difference between valid and invalid date objects in JS, but couldn't figure out how: var d = new Date("foo"); console.log(d.toString()); // shows 'Invalid Date' console.log(...
  • 70.9k
555 votes
33 answers
1.1m views

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?
  • 9,461
587 votes
29 answers
1.7m views

jQuery UI DatePicker - Change Date Format

I am using the UI DatePicker from jQuery UI as the stand alone picker. I have this code: <div id="datepicker"></div> And the following JS: $('#datepicker').datepicker(); When I ...
  • 25.3k
792 votes
24 answers
1.6m views

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 ...
  • 8,890
1059 votes
27 answers
1.0m views

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?
  • 71.8k
66 votes
3 answers
14k views

Why is the Java date API (java.util.Date, .Calendar) such a mess?

As most people are painfully aware of by now, the Java API for handling calendar dates (specifically the classes java.util.Date and java.util.Calendar) are a terrible mess. Off the top of my head: ...
  • 79k
781 votes
34 answers
1.2m views

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 ...
  • 39.5k
584 votes
23 answers
922k views

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)...
1376 votes
17 answers
1.5m views

Calculate difference between two dates (number of days)?

I see that this question has been answered for Java, JavaScript, and PHP, but not C#. So, how might one calculate the number of days between two dates in C#?
  • 181k
96 votes
23 answers
161k views

Get a list of dates between two dates

Using standard mysql functions is there a way to write a query that will return a list of days between two dates. eg given 2009-01-01 and 2009-01-13 it would return a one column table with the values:...
  • 1,097
1263 votes
42 answers
1.7m views

How to get current time and date in Android

How can I get the current time and date in an Android app?
  • 12.7k
93 votes
5 answers
34k views

Y returns 2012 while y returns 2011 in SimpleDateFormat

I wonder why 'Y' returns 2012 while 'y' returns 2011 in SimpleDateFormat: System.out.println(new SimpleDateFormat("Y").format(new Date())); // prints 2012 System.out.println(new SimpleDateFormat("y")....
  • 113k
16 votes
3 answers
29k views

How are dates stored in Oracle?

How are dates stored in Oracle? For example I know most systems use Epoch time to determine what time it is. By calculating how many seconds away from January 1st 1970. Does Oracle do this as well? ...
  • 7,643
945 votes
40 answers
1.3m views

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");
  • 209k
189 votes
23 answers
281k views

Get week of year in JavaScript like in PHP

How do I get the current weeknumber of the year, like PHP's date('W')? It should be the ISO-8601 week number of year, weeks starting on Monday.
  • 70.1k
365 votes
26 answers
680k views

How to format date and time in Android?

How to format correctly according to the device configuration date and time when having a year, month, day, hour and minute?
  • 273k
379 votes
16 answers
812k views

How to add number of days to today's date? [duplicate]

I need to be able to add 1, 2 , 5 or 10 days to today's date using jQuery.
  • 3,827
382 votes
30 answers
276k views

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 ...
  • 21.9k

1
2 3 4 5
164