IT Community - Software Programming, Web Development and Technical Support

How can I compare a date in a string with todays date?

This is a discussion on How can I compare a date in a string with todays date? within the HTML, CSS and Javascript Coding Techniques forums, part of the Web Development category; Hi all... How can I compare a date in a string with todays date? Thanks......


Go Back   IT Community - Software Programming, Web Development and Technical Support > Web Development > HTML, CSS and Javascript Coding Techniques

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 12-16-2007, 09:20 PM
itbarota itbarota is offline
D-Web Architect
 
Join Date: Jun 2007
Posts: 547
itbarota is on a distinguished road
Default How can I compare a date in a string with todays date?

Hi all...


How can I compare a date in a string with todays date?

Thanks...
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 12-16-2007, 09:31 PM
Pvinothkumar Pvinothkumar is offline
D-Web Analyst
 
Join Date: Sep 2007
Posts: 237
Pvinothkumar is on a distinguished road
Default Re: How can I compare a date in a string with todays date?

Hi all...


<script language="JavaScript">
function isitToday(dateString,dateType) {
var now = new Date();
var today = new Date(now.getYear(),now.getMonth(),now.getDate());

if (dateType == 1)
var date = new Date(dateString.substring(0,4),
dateString.substring(4,6)-1,
dateString.substring(6,8));
else if (dateType == 2)
var date = new Date(dateString.substring(0,2),
dateString.substring(2,4)-1,
dateString.substring(4,6));
else if (dateType == 3)
var date = new Date(dateString.substring(6,10),
dateString.substring(3,5)-1,
dateString.substring(0,2));
else if (dateType == 4)
var date = new Date(dateString.substring(6,8),
dateString.substring(3,5)-1,
dateString.substring(0,2));
else
return false;

if (date.toString() == today.toString())
return true;
else
return false;
}

if (isitToday("19970529",1)) alert('true'); else alert('false');

if (isitToday("970529",2)) alert('true'); else alert('false');

if (isitToday("29/05/1997",3)) alert('true'); else alert('false');

if (isitToday("02/06/97",4)) alert('true'); else alert('false');
</script>

Thanks...
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 12-18-2007, 11:02 PM
kingmaker kingmaker is offline
D-Web Genius
 
Join Date: Jun 2007
Posts: 882
kingmaker is on a distinguished road
Send a message via Yahoo to kingmaker
Smile Re: How can I compare a date in a string with todays date?

<script language="text/javascript">
function lastMod() {
var x = new Date (document.lastModified);
Modif = new Date(x.toGMTString());
Year = takeYear(Modif);
Month = Modif.getMonth();
Day = Modif.getDate();
Mod = (Date.UTC(Year,Month,Day,0,0,0))/86400000;
x = new Date();
today = new Date(x.toGMTString());
Year2 = takeYear(today);
Month2 = today.getMonth();
Day2 = today.getDate();
now = (Date.UTC(Year2,Month2,Day2,0,0,0))/86400000;
daysago = now - Mod;
if (daysago < 0) return '';
unit = 'days';
if (daysago > 730) {
daysago = Math.floor(daysago/365);
unit = 'years';
}
else if (daysago > 60) {
daysago = Math.floor(daysago/30);
unit = 'months';
}
else if (daysago > 14) {
daysago = Math.floor(daysago/7);
unit = 'weeks'
}
var towrite = 'Page last changed ';
if (daysago == 0) towrite += 'today';
else if (daysago == 1) towrite += 'yesterday';
else towrite += daysago + ' ' + unit + ' ago';
return towrite;
}


function takeYear(theDate) {
x = theDate.getYear();
var y = x % 100;
y += (y < 38) ? 2000 : 1900;
return y;
}

document.write(lastMod())
</script>
__________________
The KINGMAKER
Makes Every Thing Possible

Stuffs (My Blog)
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Check that a string contains a date. itbarota HTML, CSS and Javascript Coding Techniques 2 03-11-2008 09:01 PM
Convert String to Date: new Date(string) oxygen Flash Actionscript Programming 3 03-07-2008 09:24 PM
Convert a date in milliseconds back to a date string itbarota HTML, CSS and Javascript Coding Techniques 2 03-03-2008 09:03 PM
How can I show the documents last modified date in the format: month, date, year, tim Pvinothkumar HTML, CSS and Javascript Coding Techniques 3 12-28-2007 05:58 AM
How to convert a date to a globally accepted date format, in DOT NET 2005? Archer C# Programming 1 07-25-2007 03:21 AM


All times are GMT -7. The time now is 01:18 PM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0