Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

Reply
Regular Contributor
yamafarooq
Posts: 65
Registered: ‎01-03-2013
My Device: 9810
My Carrier: Tmobile
Accepted Solution

How to change date to milliseconds

hello guys i am working on a new project where the user need to add his date of birth, i want to have some type of validation to check if the user is entring correct date of brith "not same day or futuer date", the date user entering into filed comes in this format " 2013-07-05" in order to do validation i have to change it to milliseconds.

 

Is there any way to change date in this format to milliseconds?

 

or any other way to do validation 

 

Thanks for help 

-----
Please press the like button to thank the user that helped you.
Accept as a solution if it solved the problem.
Cheers
Please use plain text.
Developer
PawelGorny
Posts: 148
Registered: ‎12-03-2012
My Device: RED
My Carrier: base(kpn)/BE, t-mobile/PL

Re: How to change date to milliseconds


yamafarooq wrote:

hello guys i am working on a new project where the user need to add his date of birth, i want to have some type of validation to check if the user is entring correct date of brith "not same day or futuer date", the date user entering into filed comes in this format " 2013-07-05" in order to do validation i have to change it to milliseconds.

 

Is there any way to change date in this format to milliseconds?

 

or any other way to do validation 

 

Thanks for help 


http://www.w3schools.com/jsref/jsref_obj_date.asp

var d = new Date(2013, (7-1), 5, 0, 0, 0, 0);

d.getTime();

--
Regards,
Pawel Gorny
my apps: http://pawelgorny.com/
PGpgp, Your Reply, Anagrammatist, Texas Hold'em Odds Calculator, Contacts to CSV
If your issue has been solved, please resolve it by marking "Accept as Solution"
Please use plain text.
Developer
peardox
Posts: 1,229
Registered: ‎03-20-2011
My Device: Playbook, Z10 LE, Dev Alpha B, 2x Dev Alpha C
My Carrier: 3, Orange, Vodafone

Re: How to change date to milliseconds

www.w3schools.com/jsref/jsref_gettime.asp

 

You just need to change that into the format you need

 

Not knowing your exact requirements - that's about the best help I can give

 

If you look deeped into the Date object you may get exactly your desired result




Click the like button if you find my posts useful!
Please use plain text.
BlackBerry Development Advisor
oros
Posts: 1,557
Registered: ‎04-12-2010
My Device: BlackBerry Z10
My Carrier: Bell

Re: How to change date to milliseconds

yamafarooq, did any of the replies above answer your question? If so, can you please Accept as Solution on the response and, if not, let us know the issues you're still seeing and we'll do our best to help.

Erik Oros | @WaterlooErik | eoros@blackberry.com | Developer Issue Tracker

If a reply has answered your question, please click Accept as Solution to help other visitors in the future.
Please use plain text.
Regular Contributor
yamafarooq
Posts: 65
Registered: ‎01-03-2013
My Device: 9810
My Carrier: Tmobile

Re: How to change date to milliseconds

[ Edited ]

Sorry for let reply, 

 

the above answers were helpful but, still didnt solved my problem . i want to change the date into milliseconds in order to compare two dates  and find exact age of person, person could be a kid age of 2 days or one month or whatever .

 

Thank you very much everyone for hlep , 

 

I will really appreciate if anyone of you hlep me 

 

Regards 

 

-----
Please press the like button to thank the user that helped you.
Accept as a solution if it solved the problem.
Cheers
Please use plain text.
BlackBerry Development Advisor
oros
Posts: 1,557
Registered: ‎04-12-2010
My Device: BlackBerry Z10
My Carrier: Bell

Re: How to change date to milliseconds

The samples here may be of interest:

http://www.javascriptkit.com/javatutors/datedifference.shtml

 

Specifically, once you create yoru two date objects (i.e. birthday and today) you can use the getTime() function and subtract the two (today - birthday) to get the elapsed time in milliseconds.

 

From there, it would be a matter of some mathemagic on the elapsed time to pull out the seconds, minutes, hours, days, months, years, etc. of that person's age.

 

This post here has some good information (including a getAge implementation) that might be useful for the second part.

http://stackoverflow.com/questions/11570232/javascript-calculate-years-and-days-from-start-date


Erik Oros | @WaterlooErik | eoros@blackberry.com | Developer Issue Tracker

If a reply has answered your question, please click Accept as Solution to help other visitors in the future.
Please use plain text.
Regular Contributor
yamafarooq
Posts: 65
Registered: ‎01-03-2013
My Device: 9810
My Carrier: Tmobile

Re: How to change date to milliseconds

[ Edited ]

After spending 2 hours I come out with a solution by myselfhowever the function can be customize to check if the user is entering right date.

 

function findtAge(subjectName,fromdate, todate) {
	console.log("findAge(fromdate, todate) is called now "+subjectName+"-->"+fromdate+"-->"+todate);
    if(todate) todate= new Date(todate);
    else todate= new Date();

    var age= [], fromdate= new Date(fromdate),
    y= [todate.getFullYear(), fromdate.getFullYear()],
    ydiff= y[0]-y[1],
    m= [todate.getMonth(), fromdate.getMonth()],
    mdiff= m[0]-m[1],
    d= [todate.getDate(), fromdate.getDate()],
    ddiff= d[0]-d[1];

    if(mdiff < 0 || (mdiff=== 0 && ddiff<0))--ydiff;
    if(mdiff<0) mdiff+= 11;
    if(ddiff<0){
        fromdate.setMonth(m[1]+1, 0);
        ddiff= fromdate.getDate()-d[1]+d[0];
        --mdiff;
    }
    if(ydiff> 0) age.push(ydiff+ ' year'+(ydiff> 1? 's ':' '));
    if(mdiff> 0) age.push(mdiff+ ' month'+(mdiff> 1? 's':''));
    if(ddiff> 0) age.push(ddiff+ ' day'+(ddiff> 1? 's':''));
    if(age.length>1) age.splice(age.length-1,0,' and ');
    console.log("===============================");
    console.log("Subject age is = "+age.join(''));
    console.log(" age Day = "+ddiff);
    console.log(" age Month = "+mdiff);
    console.log(" age Year = "+ydiff);
    console.log("===============================");
    var subjectAGE =  age.join('');
    
}

 Thank you very much guys for helpful replies 

 

-----
Please press the like button to thank the user that helped you.
Accept as a solution if it solved the problem.
Cheers
Please use plain text.