[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Date Hours Minutes and AM/PM in javascript function

Posted on 2006-11-16
1
Medium Priority
?
1,134 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 2

Accepted Solution

by:
Messiadbunny earned 1500 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
This article discusses how to create an extensible mechanism for linked drop downs.
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…

650 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