Welcome to Dream.In.Code
Become an Expert!

Join 150,423 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,100 people online right now. Registration is fast and FREE... Join Now!




converting date in day

 
Reply to this topicStart new topic

converting date in day

kumar.dinesh77
20 Mar, 2008 - 09:07 PM
Post #1

New D.I.C Head
*

Joined: 20 Mar, 2008
Posts: 1

jscript

function compare(txtFrom,txtTo)
{

var a = txtFrom;
var b = txtTo;
var x=a.split('/');
var y=b.split('/');
var oneday=1000*60*60*24;
var dateto=new Date(x[1]-1,x[2],x[0]);
var datefrom=new Date(y[1]-1,y[2],y[0]);
var month1=x[1]-1;
var month2=y[1]-1;

var diff=Math.ceil((datefrom.getTime()-dateto.getTime())/(oneday));




if(diff>=0)
{
alert(diff);
alert("true");

return true;
}

else
{
alert(diff);
alert("false");
alert('in any of the field u have insert wrong:to date>from date');

return false;
}



}


above code is done on javascript for chacking of date
requirement is from date must be less than todate ex-from 03/12/2008 to 03/20/2008 this is correct date and code work properly but if i do like from 03/18/2007 to 03/02/2008 this is correct date but this code is not working.pls guide me

This post has been edited by PsychoCoder: 20 Mar, 2008 - 09:36 PM
User is offlineProfile CardPM
+Quote Post

PsychoCoder
RE: Converting Date In Day
20 Mar, 2008 - 09:37 PM
Post #2

using DIC.Core;
Group Icon

Joined: 26 Jul, 2007
Posts: 9,483



Thanked: 161 times
Dream Kudos: 9075
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions
Moved to the JavaScript Forum
User is offlineProfile CardPM
+Quote Post

ahmad_511
RE: Converting Date In Day
22 Mar, 2008 - 12:33 PM
Post #3

D.I.C Regular
Group Icon

Joined: 28 Apr, 2007
Posts: 351



Thanked: 8 times
Dream Kudos: 400
My Contributions
Hello.
I tried your example and it's giving the same result but one of them is negative.
if the nigative value is what you're concerned about you can use Math.abs() toconvert it to a positive value

Regards
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 08:32PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month