Click here to Skip to main content
15,905,590 members
Home / Discussions / Web Development
   

Web Development

 
GeneralRe: Adding number of days to a Date Pin
Ph@ntom20-Jul-04 19:13
Ph@ntom20-Jul-04 19:13 
GeneralRe: Adding number of days to a Date Pin
Alexander Wiseman21-Jul-04 3:31
Alexander Wiseman21-Jul-04 3:31 
GeneralRe: Adding number of days to a Date Pin
Ph@ntom23-Jul-04 17:48
Ph@ntom23-Jul-04 17:48 
GeneralRe: Adding number of days to a Date Pin
Alexander Wiseman25-Jul-04 3:22
Alexander Wiseman25-Jul-04 3:22 
GeneralRe: Adding number of days to a Date Pin
Ph@ntom25-Jul-04 6:16
Ph@ntom25-Jul-04 6:16 
GeneralRe: Adding number of days to a Date Pin
Ph@ntom26-Jul-04 6:12
Ph@ntom26-Jul-04 6:12 
GeneralRe: Adding number of days to a Date Pin
Alexander Wiseman27-Jul-04 8:00
Alexander Wiseman27-Jul-04 8:00 
GeneralRe: Adding number of days to a Date Pin
Ph@ntom27-Jul-04 19:40
Ph@ntom27-Jul-04 19:40 
First I found that javascript function getMonth() always starts from zero

I copied it as it is from the above reply!


This is the place where I am calling it

FormatDate(AddDayToDate(FormatDate(document.frmEngine.PLREMDATE.value,"yyyy/mm/dd"), 0), "dd/mm/yyyy") ;


// Definition of AddDayToDate<br />
function AddDayToDate(plandate, days)<br />
{<br />
	var gCurrentDate = new Date(plandate)<br />
	<br />
		var newDate = DateAdd(gCurrentDate, parseInt(days,10), <br />
						parseInt(0,10), <br />
						parseInt(0,10));	<br />
			<br />
	var year = newDate.getFullYear()  ; <br />
	var month = newDate.getMonth() ;<br />
	var date = newDate.getDate() ;<br />
	return date + "/" + month + "/" + year ;<br />
}






// Definition of FormatDate function<br />
function FormatDate(DateToFormat,FormatAs)<br />
{<br />
	if(DateToFormat=="")<br />
	{<br />
		return"";<br />
	}<br />
	<br />
	if(!FormatAs){FormatAs="dd/mm/yyyy";}<br />
<br />
	var strReturnDate;<br />
	<br />
	FormatAs = FormatAs.toLowerCase();<br />
	<br />
	DateToFormat = DateToFormat.toLowerCase();<br />
	<br />
	var arrDate<br />
	<br />
	var arrMonths = new Array("January","February","March","April","May","June","July","August","September","October","November","December");<br />
	<br />
	var strMONTH;<br />
	<br />
	var Separator;<br />
<br />
	while(DateToFormat.indexOf("st")>-1)<br />
	{	<br />
		DateToFormat = DateToFormat.replace("st","");<br />
	}<br />
<br />
	while(DateToFormat.indexOf("nd")>-1)<br />
	{<br />
		DateToFormat = DateToFormat.replace("nd","");<br />
	}<br />
<br />
	while(DateToFormat.indexOf("rd")>-1)<br />
	{<br />
		DateToFormat = DateToFormat.replace("rd","");<br />
	}<br />
<br />
	while(DateToFormat.indexOf("th")>-1)<br />
	{<br />
		DateToFormat = DateToFormat.replace("th","");<br />
	}<br />
<br />
	if(DateToFormat.indexOf(".")>-1)<br />
	{<br />
		Separator = ".";<br />
	}<br />
<br />
	if(DateToFormat.indexOf("-")>-1)<br />
	{<br />
		Separator = "-";<br />
	}<br />
<br />
<br />
	if(DateToFormat.indexOf("/")>-1)<br />
	{<br />
		Separator = "/";<br />
	}<br />
<br />
	if(DateToFormat.indexOf(" ")>-1)<br />
	{<br />
		Separator = " ";<br />
	}<br />
<br />
	arrDate = DateToFormat.split(Separator);<br />
	DateToFormat = "";<br />
<br />
	for(var iSD = 0;iSD < arrDate.length;iSD++)<br />
	{<br />
		if(arrDate[iSD]!="")<br />
		{<br />
			DateToFormat += arrDate[iSD] + Separator;<br />
		}<br />
	}<br />
	<br />
	DateToFormat = DateToFormat.substring(0,DateToFormat.length-1);<br />
	arrDate = DateToFormat.split(Separator);<br />
<br />
	if(arrDate.length < 3)<br />
	{<br />
		return "";<br />
	}<br />
<br />
	var DAY = arrDate[0];<br />
	var MONTH = arrDate[1];<br />
	var YEAR = arrDate[2];<br />
<br />
	if(parseFloat(arrDate[1]) > 12)<br />
	{<br />
		DAY = arrDate[1];<br />
		MONTH = arrDate[0];<br />
	}<br />
<br />
	if(parseFloat(DAY) && DAY.toString().length==4)<br />
	{<br />
		YEAR = arrDate[0];<br />
		DAY = arrDate[2];<br />
		MONTH = arrDate[1];<br />
	}<br />
<br />
<br />
	for(var iSD = 0;iSD < arrMonths.length;iSD++)<br />
	{<br />
		var ShortMonth = arrMonths[iSD].substring(0,3).toLowerCase();<br />
		var MonthPosition = DateToFormat.indexOf(ShortMonth);<br />
		if(MonthPosition > -1)<br />
		{<br />
			MONTH = iSD + 1;<br />
			if(MonthPosition == 0)<br />
			{<br />
				DAY = arrDate[1];<br />
				YEAR = arrDate[2];<br />
			}<br />
			break;<br />
		}<br />
	}<br />
<br />
	var strTemp = YEAR.toString();<br />
<br />
	if(strTemp.length==2)<br />
	{<br />
		if(parseFloat(YEAR)>40)<br />
		{<br />
			YEAR = "19" + YEAR;<br />
		}<br />
		else<br />
		{<br />
			YEAR = "20" + YEAR;<br />
		}<br />
	}<br />
<br />
<br />
	if(parseInt(MONTH)< 10 && MONTH.toString().length < 2)<br />
	{<br />
		MONTH = "0" + MONTH;<br />
	}<br />
	<br />
	if(parseInt(DAY)< 10 && DAY.toString().length < 2)<br />
	{<br />
		DAY = "0" + DAY;<br />
	}<br />
	<br />
	switch (FormatAs)<br />
	{<br />
		case "dd/mm/yyyy":<br />
			return DAY + "/" + MONTH + "/" + YEAR;<br />
		case "mm/dd/yyyy":<br />
			return MONTH + "/" + DAY + "/" + YEAR;<br />
		case "dd/mmm/yyyy":<br />
			return DAY + " " + arrMonths[MONTH -1].substring(0,3) + " " + YEAR;<br />
		case "mmm/dd/yyyy":<br />
			return arrMonths[MONTH -1].substring(0,3) + " " + DAY + " " + YEAR;<br />
		case "dd/mmmm/yyyy":<br />
			return DAY + " " + arrMonths[MONTH -1] + " " + YEAR;	<br />
		case "mmmm/dd/yyyy":<br />
			return arrMonths[MONTH -1] + " " + DAY + " " + YEAR;<br />
		case "yyyy/mm/dd":<br />
			return YEAR + " " + arrMonths[MONTH -1] + " " + DAY ;<br />
	}<br />
<br />
	return DAY + "/" + strMONTH + "/" + YEAR;;<br />
<br />
} //End Function




Regards,

The Phantom.
GeneralRe: Adding number of days to a Date Pin
Alexander Wiseman28-Jul-04 4:31
Alexander Wiseman28-Jul-04 4:31 
GeneralRe: Adding number of days to a Date Pin
Ph@ntom30-Jul-04 18:57
Ph@ntom30-Jul-04 18:57 
GeneralRe: Adding number of days to a Date Pin
Alexander Wiseman2-Aug-04 7:15
Alexander Wiseman2-Aug-04 7:15 
GeneralCalling Web Services from a web page Pin
NiteShade19-Jul-04 6:36
NiteShade19-Jul-04 6:36 
GeneralRe: Calling Web Services from a web page Pin
VenkatFor.NET21-Jul-04 8:08
VenkatFor.NET21-Jul-04 8:08 
GeneralRe: Calling Web Services from a web page Pin
mysorian11-Aug-04 11:41
professionalmysorian11-Aug-04 11:41 
GeneralLocalHost and Browser Pin
ohdil16-Jul-04 8:41
ohdil16-Jul-04 8:41 
GeneralRe: LocalHost and Browser Pin
Javier Lozano18-Jul-04 17:01
Javier Lozano18-Jul-04 17:01 
GeneralRe: LocalHost and Browser Pin
ohdil22-Jul-04 13:40
ohdil22-Jul-04 13:40 
GeneralRe: LocalHost and Browser Pin
Javier Lozano22-Jul-04 14:18
Javier Lozano22-Jul-04 14:18 
GeneralGarbage Collection in JS Pin
abc87616-Jul-04 0:15
abc87616-Jul-04 0:15 
GeneralAWS Report for OpenListing Pin
Sumit Kapoor15-Jul-04 21:24
Sumit Kapoor15-Jul-04 21:24 
GeneralRe: AWS Report for OpenListing Pin
zahedonline30-Oct-08 3:41
zahedonline30-Oct-08 3:41 
GeneralHere's a curly one... Pin
Anonymous15-Jul-04 20:20
Anonymous15-Jul-04 20:20 
GeneralRe: Here's a curly one... Pin
Javier Lozano18-Jul-04 17:00
Javier Lozano18-Jul-04 17:00 
Generalthe selectList can't make selected in Netscape... Pin
cool_man15-Jul-04 17:10
cool_man15-Jul-04 17:10 
QuestionCSS Borders Always White??? Pin
Josh Koppang15-Jul-04 12:57
Josh Koppang15-Jul-04 12:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.