date function

Ads
 

date function

Write a JavaScript program to read a date from user and perform the following, if entered value is date then perform the following 1. Display the day no from the date 2. Display the year from the date 3. Display the month from the date 4. Change the date to next day 5. Change the year to next year 6. change the month to next month

View Answers

March 12, 2011 at 5:41 PM

<html>
<script type="text/javascript">
function checkdate(){
var input=document.getElementById('mydate');
var validformat=/^\d{2}\/\d{2}\/\d{4}$/ 
var returnval=false
if(!validformat.test(input.value))
alert("Invalid Date Format!")
else{ 
var monthfield=input.value.split("/")[0]
var dayfield=input.value.split("/")[1]
var yearfield=input.value.split("/")[2]
document.getElementById("no").value=dayfield;
document.getElementById("month").value=monthfield;
document.getElementById("year").value=yearfield;
document.getElementById("nextno").value=parseInt(dayfield)+1;
document.getElementById("nextmonth").value=parseInt(monthfield)+1;
document.getElementById("nextyear").value=parseInt(yearfield)+1;

var dayobj = new Date(yearfield, monthfield-1, dayfield)
if ((dayobj.getMonth()+1!=monthfield)||(dayobj.getDate()!=dayfield)||(dayobj.getFullYear()!=yearfield))
alert("Invalid Day, Month, or Year range!")
else
returnval=true
}
if(returnval==false) input.select()
return returnval
}
</script>
Enter date (mm/dd/yyyy):<input type="text" id="mydate" />
<input type="button" value="submit" onclick="checkdate();"><br />
<pre>
Day No     <input type="text" id="no">
Month      <input type="text" id="month">
Year       <input type="text" id="year">
Next Day   <input type="text" id="nextno">
Next Month <input type="text" id="nextmonth">
Next Year  <input type="text" id="nextyear">
</pre>
</html>

Ads









Related Tutorials/Questions & Answers:
date function
date function  Write a JavaScript program to read a date from user and perform the following, if entered value is date then perform the following 1. Display the day no from the date 2. Display the year from the date 3. Display
Mysql Date now function
Mysql Date now function       Mysql Date now function is useful when you want to return the current... 'Mysql Date now function'. In this Tutorial we define a now ( ) Query
Advertisements
Mysql Date Parse
Mysql Date Parse       Mysql Date is used to parse the string date time in Date Format function and retrieve the date in specified format. Understand with Example The Tutorial
function
function  difference between function overloading and operator overloading
date
date   how to insert date in database? i need coding
date
date  can u tell me how to calculate difference between a user provided date and the system date in java
date
date  i want difference between the date entered in a jtextfield and the system date in java
date
date  can u tell me how to calculate difference between a user provided date and the system date in java
date
date  how to insert date using html through the combobox
date
date  how to insert date using html through the combobox
date
date  how to insert date using html through the combobox
date
date  how to insert date using html through the combobox
SQL NOW() Function
SQL NOW() Function         NOW ( ) Function provides you the current date and time... date and time. The Now( ) function return you the current date and time
date
database table name birthday (DOB date); dob with DATE data type in database while...=d.getTime(); java.sql.Date date = new java.sql.Date(t); try { System.out.println(date); Class.forName("oracle.jdbc.OracleDriver"); con
DATE
DATE  I have the following as my known parameter Effective Date... of calcultion starts My question is how to find the date of Thursday This cycle... the date of all the thursdays of the given year. import java.util.*; import
php date input calendar
php date input calendar  I'm having an issue while writing the date input calendar function in PHP.. any help? Thanks
jquery start date end date validation
jquery start date end date validation  Using JQuery how can i validate the end date and start date? for example if the start date is grater than the end date?   jQuery.validator.addMethod("greaterThan", function(value
Date auto format
Date auto format  Hi, I have jsp page and Date field with input type. Requirement is, if we enter date as MMDDYY or MMDDYYYY and clicking the tab the date(MMDDYY or MMDDYYYY) have to auto format to MM/DD/YYYY. could you please
function addValue
function addValue  i have question about the javascript the function addvalue script is working to add some name but is not save on the html so please resolve my problem what can i do for addvalue function will be to save
function addValue
function addValue  i have question about the javascript the function addvalue script is working to add some name but is not save on the html so please resolve my problem what can i do for addvalue function will be to save
function addValue
function addValue  i have question about the javascript the function addvalue script is working to add some name but is not save on the html so please resolve my problem what can i do for addvalue function will be to save
JQuery date change event
JQuery date change event  JQuery date change event I have been designing a date form in HTML and JQuery, wher i need two different date vales start date and end date for any event. I have already writen a function that allows
Calling a function
Calling a function  Hi, I have a function xyz() in php code. When a button is clicked it should execute that particular function for that i have... function function xyz() { } but this is not working can u tell me
function method
function method  input Rs. 12000 Discount= 10%, 8% = Rs.(12000-1200) = Rs.(10800-864) = Rs. 9936
using function
using function   using a function to find the value of v from the foiiowing expression 1v=1u+1*f
If function in PHP
If function in PHP  Hi, Provide me the example of If function in PHP. Thanks   Hi, If function is PHP is used to check for some condition and the execute a block of code. He is an example of if() function in PHP
function method
function method  input Rs. 12000 Discount= 10%, 8% = Rs.(12000-1200) = Rs.(10800-864) = Rs. 9936
disable function
disable function  Sir, I have called a java script function when one radio button is checked i want to disable this function when another radio button is checked ,both radio buttons are of same group Please help Thanks in advance
convert current date into date format
convert current date into date format  How to get current date and convert into date format in Java or PHP
date convertion
date convertion  How to convert the string date format 23/11/2009 to original date format in asp.net
unoin function
unoin function  how to define a union function in java?(ex:a=a U b) how to write tha java code?give ex.   Java Union Function You have learnt union, intersection etc in Sets. Here the given code finds the union of two

Ads