Solved

Add 30 minutes to datetime in Javascript

Posted on 2006-11-15
9
4,145 Views
Last Modified: 2008-01-09
Hello,

I am using rainforestnet.com javascript calendar popup control. Say if the date is 11/15/2006 02:20 PM How do I add 30 minutes to this??

what I want is, whatever is the datetime I need to add 30 minutes to that.

Please help

thanks
0
Comment
Question by:rowmark
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 17947379
x=new Date("11/15/2006 02:20 PM")
x.setMinutes(x.getMinutes()+30)
0
 
LVL 41

Expert Comment

by:HonorGod
ID: 17947454
// Assuming that the result date from the javascript popup is put into resultDate...

 var delta = 30 * 60 * 1000;  // Milliseconds in 30 minutes

 var date =  new Date( resultDate.parse() + delta );
0
 
LVL 23

Expert Comment

by:rama_krishna580
ID: 17947956
Hi,

try this..
<script language=javascript>
d=new Date()

Theday = d.getDay()+1

if(Theday < 10)
{
Theday = "0"+Theday}
TheMonth = d.getMonth()+1

if(TheMonth < 10)
{
TheMonth = "0"+TheMonth}
TheDate = Theday + "/" + TheMonth + "/" + d.getFullYear()
TheMinute = d.getMinutes() + 30
TheHour = d.getHours()

TheTime = TheHour + ":" +TheMinute
DateNow = TheDate + TheTime

</script>
R.K
0
 

Author Comment

by:rowmark
ID: 17949089
On click of this hyperlink

PCellStr="<td "+vColor+" width="+CellWidth+" align='center'><font face='verdana' size='2'"+vHLstr1+"<a href=\"javascript:winMain.document.getElementById('"+Cal.Ctrl+"').value='"+Cal.FormatDate(PValue)+"';"+vTimeStr+";winMain.document.getElementById('"+Cal.NCtrl+"').value='"+Cal.FormatDate(PValue)+"';"+vTimeStr1+";window.close();\">"+PValue+"</a>"+vHLstr2+"</font></td>";

Now this is Cal.FormatDate(PValue)+"';"+vTimeStr1+"; I need to add 30 minutes.

When I try to do this
var finalDateTime;
finalDateTime=new Date(Cal.FormatDate(PValue)+''+vTimeStr1) ;
finalDateTime=finalDateTime.setMinutes(x.getMinutes()+30)

Its throwing out errors

Please help
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 500 total points
ID: 17950248
var finalDateTime = new Date(Cal.FormatDate(PValue)+''+vTimeStr1) ;
finalDateTime.setMinutes(finalDateTime.getMinutes()+30)
0
 

Author Comment

by:rowmark
ID: 17962581
thanks mplungjan. Even after doign that it is not working. It is throwing out errors
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 17962873
pls be more specific. the code I gave should not affect your code
If the date is valid, then adding 30 to it will not affect anything
0
 
LVL 41

Expert Comment

by:HonorGod
ID: 17964927
What is the exact value in PValue?
0
 
LVL 41

Expert Comment

by:HonorGod
ID: 17965213
rowmark:
  Your TD code is ugly... :-)..  no, no, make that "hard to read", yeah, that's better...  :-)

  It would be much better for you to simplify things, and create a function to do the things that you are trying to do in the in-line code.
  It would also be better to make use of CSS to simplify your code.

  Instead of  using your very verbose

"<td " + vColor + " width=" + CellWidth + " align='center'><font face='verdana' size='2'" + vHLstr1 + ... + vHLstr2 + "</font>

  define a style for your TD, and use something like:

"<td class='myClass'>" + ... + "<\/td>"

The style section of your <head> might look something like:

<style type='text/css'>
.myClass {
   font-size  : small;
   font-style : Verdana;
   color : Yellow;
   background-color : Green;
}
</style>
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
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…

895 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now