I have a date range like 12/20/12-12/24/12(start date-end date) in string format . I need to check if start date has past the present date. Can it be done using JS or j-query? the date range is in string ?
Asked
Active
Viewed 3,892 times
0
-
1Yes, it can be done in JavaScript. Have you tried anything? Done any research? – T.J. Crowder Dec 12 '12 at 16:04
-
No, you cannot use jQuery for date stuff. – Bergi Dec 12 '12 at 16:04
-
http://stackoverflow.com/a/5619588/1643087 ... this article gives a way to convert string intoo date but the format am not sure of ... i need it to be converted into MM/DD/YYYY – user1643087 Dec 12 '12 at 16:10
-
javascript has a load of (admittedly not very good) built in Date (http://www.w3schools.com/js/js_obj_date.asp) functions and plenty of string functions to aid in splitting them up. – totallyNotLizards Dec 13 '12 at 09:24
3 Answers
0
thanx evry1 .. i got the answer here it is ...
function cancel()
{
var eventId=status_ID.substr(0,status_ID.indexOf("-"));
var status=status_ID.substr(status_ID.indexOf("-")+1,status_ID.indexOf(":")-4);
var eventRange=status_ID.substr(status_ID.indexOf(":")+1,status_ID.length);
//alert(status);
//alert(eventRange);
if(status=="OPEN"){
var startDate = eventRange.substr(0,eventRange.indexOf("-"));
//alert(startDate);
// alert("open");
var todayDay = new Date().getDate();
// alert(todayDay);
var todayMonth = new Date().getMonth();
alert(todayMonth);
var todayFullYear = new Date().getFullYear();
var todayYear=todayFullYear.toString().substr(2,4);
// alert(todayYear);
parts = startDate.split("/");
//alert(parts[0]);
//alert(parts[1]);
//alert(parts[2]);
var flag1=false;
if(parts[2]>todayYear){
flag1=true;
}
if(parts[2]==todayYear){
if(parts[1]>todayMonth+1)
{
flag1=true;
}
if(parts[1]==todayMonth+1)
{
if(parts[0]>todayDay)
{
flag1=true;
}
}
}
if(flag1)
{
alert("event can be cancelled");
document.forms[0].submit();
}
else
{
alert("event has already started");
return false;
}
}
else
{
alert("The event has closed");
}
}

user1643087
- 643
- 1
- 6
- 11