Solved

Date Hours Minutes and AM/PM in javascript function

Posted on 2006-11-16
1
1,123 Views
Last Modified: 2012-06-27
In my javascript function I am getting date value as show below

var sDate=Cal.FormatDate(PValue);
var sHours=winMain.Cal.getShowHour();
var sMinutes=winMain.Cal.Minutes;
var sAMPM=winMain.Cal.AMorPM;

when we consolidate all the above the final date will look like eg: 11/16/2006 03:15 PM

Now I want to add 30 Minutes to the minutes which should take all the following scenarios: like if I add 30 minutes to
11/16/2006 11:45 PM
it should show  11/17/2006 00:15 AM

and so on

Please help
0
Comment
Question by:rowmark
1 Comment
 
LVL 2

Accepted Solution

by:
Messiadbunny earned 500 total points
ID: 17962877
<script type="text/javascript">

curdate = new Date()

dateVar = new Date(curdate.getFullYear(), curdate.getMonth(), curdate.getDate(),curdate.getHours(),curdate.getMinutes() + 30,curdate.getSeconds())
//This collects all the data from the current date, except adds 30 mins as shown above
// curdate.getMinutes() + 30 is the specific line that adds 30 mins.

if (dateVar.getHours() < 12 & dateVar.getHours() > 0)
{
//If time is less than noon, but before 1 AM
curhour = dateVar.getHours()
ampm = "A.M."
}
else if (dateVar.getHours() == 12)
{
//If it's exactly 12 PM (Noon ish)
curhour = 12
ampm = "P.M."
}
else if (dateVar.getHours() == 0)
{
//1 AM in the morning
curhour = 1
ampm = "A.M."
}
else
{
//If it's any other time, 1 PM - 12 PM
curhour = dateVar.getHours() - 12
ampm = "P.M."
}

mdhour = curhour
mdminute = dateVar.getMinutes()
mdyear = dateVar.getFullYear()
mdmonth = dateVar.getMonth()
mdday = dateVar.getDate()

//re-collect all the variables incase the day/month/year/ have changed with the addition of //30 mins.

document.write(mdmonth + "/" + mdday + "/" + mdyear + " " + mdhour + ":" + mdminute + " " + ampm)




</script>
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Javascript to set controls visibility 5 34
how can i select 4 29
Web forms being filled out by bots 4 31
How to check and insure value only has 5  numbers (0-9)? 2 18
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question