Return to Snippet

Revision: 37254
at December 7, 2010 07:32 by bullzito


Initial Code
var now = new Date();
	var year, month, day, mins, sec;

		//get the current date          //add a zero for single digit values
		year    = now.getFullYear();    if (year < 1000) {year +- 1900;}
		month   = now.getMonth() + 1;   if (month < 10) {month = "0" + month;}
		day     = now.getDate();        if (day < 10) {day = "0" + day;}
		hrs     = now.getHours();       if (hrs < 10) {day = "0" + hrs;}
		mins    = now.getMinutes();     if (mins < 10) {mins = "0" + mins;}
		sec     = now.getSeconds();     if (sec < 10) {sec = "0" + sec;}

	//concatenate the dates into a string
	var current	= String(year) + String(month) + String(day) + String(hrs) + String(mins) + String(sec);
	//convert current time(string) to a number to compare values
	var curr	= Number(current);

	// dates represent expiration dates (YYYY MM DD HH MM SS)
	var A	= 20101203160800;
	var B	= 20101203161400;
	var C	= 20101203152900;

	if (A > curr) {
		$('#status').html('This is A');
	}
	else if (B > curr) {
		$('#status').html('This is B');
	}
	else if (C > curr) {
		$('#status').html('This is C');
	}
	else {
		$('#status').html('Everything Has Expired');
	}

Initial URL
http://marioluevanos.com/playground/Compare%20Expiration%20Dates/

Initial Description
Change HTML content in your HTML by comparing expiration dates. I needed code to update ads on my site. Ads had an expiration dates so this is what I used.

Initial Title
Change or Update HTML By Comparing Expiration Dates

Initial Tags

                                

Initial Language
JavaScript