I need to check fox example 2117-09-15 00:00:41.0.
I saw similar topics but this var valid = (new Date(timestamp)).getTime() > 0;
don't work.
Asked
Active
Viewed 5,924 times
2

Александр
- 137
- 3
- 10
-
2could you give us more details and some code? – Pablo Máximo Apr 14 '16 at 07:29
-
It works: https://jsfiddle.net/x5hmyyrz/ – Rahul Tripathi Apr 14 '16 at 07:36
-
I have a variable of type Timestamp createdDate = (Timestamp)employeeObject[4];,while maintaining the form I need to check the value created Date or I get an error HTTP Status 500 – Александр Apr 14 '16 at 07:37
-
Rahul Tripathi, 2117-09-15 00:00:41.0.wrong,timestamp max value <2038 year and >1970 year – Александр Apr 14 '16 at 07:42
-
@Александр:- Read the [specs](http://ecma-international.org/ecma-262/5.1/#sec-15.9.1.1): `ECMAScript Number values can represent all integers from –9,007,199,254,740,992 to 9,007,199,254,740,992; this range suffices to measure times to millisecond precision for any instant that is within approximately 285,616 years, either forward or backward, from 01 January, 1970 UTC.` – Rahul Tripathi Apr 14 '16 at 07:45
-
Do you want to check if the current time is the same as the 2117-09-15 00:00:41.0.? – Satej S Apr 14 '16 at 07:47
-
I want to check that the values was not greater than the maximum or minimum timestamp values – Александр Apr 14 '16 at 07:50
-
MySQL 5.5 Reference Manual : The TIMESTAMP data type is used for values that contain both date and time parts. TIMESTAMP has a range of '1970-01-01 00:00:01' UTC to '2038-01-19 03:14:07' UTC. – Александр Apr 14 '16 at 07:51
2 Answers
2
If you want to check that a date is valid in MySQl then you could check that it is between some dates (min and max of mySql timestamp):
function isValid(dateString) {
var minDate = new Date('1970-01-01 00:00:01');
var maxDate = new Date('2038-01-19 03:14:07');
var date = new Date(dateString);
return date > minDate && date < maxDate;
}
Here is a fiddle for you to test: https://jsfiddle.net/x5hmyyrz/3/

tudor.gergely
- 4,800
- 1
- 16
- 22
-
Also, maybe not all browsers support date direct comparison. In that case use date.getTime() > minDate.getTime() && date.getTime() < maxDate.getTime() – tudor.gergely Apr 14 '16 at 08:04
-2
As seen here: Checking if a date is valid in javascript, maybe you can use :
var date= new Date(timestamp)
valid = (date instanceof Date && !isNaN(date.valueOf()));

Nico_
- 1,388
- 17
- 31