Page 1 of 1

Simple date function

Posted: Wed Mar 10, 2010 7:28 am
by klevis miho
How can I do a function that gets the current time then compares the current time with times from a page, and highlights the lowest time, for example:

06:00
06:10
06:30
06:45

if the current time is 06:00, then hightlight 06:00

Any help would be great appreciated.

Re: Simple date function

Posted: Wed Mar 10, 2010 7:48 am
by klevis miho
The first thing I did is to get the time(i need the time from the server):
function ttime() {
var ttime='<?php echo date("H:i", time())?>';
}

Re: Simple date function

Posted: Wed Mar 10, 2010 10:20 am
by pickle
24 hour clock?

Make a numeric equivalent of each time (600, 610, 630, 645), find the lowest one, then highlight it somehow (changing the text colour, background colour, etc)

Re: Simple date function

Posted: Wed Mar 10, 2010 10:38 am
by klevis miho
Yeah thnx but I don't know how to do it in javascript, I did it in php but now I want to convert to js.

Re: Simple date function

Posted: Wed Mar 10, 2010 2:02 pm
by pickle
Post your PHP code.

Re: Simple date function

Posted: Wed Mar 10, 2010 4:52 pm
by klevis miho
I can't paste the code here, but it goes something like this:
it gets 2 time records from the db, and checks if the time now is between those 2.

I am imaging that in javascript, to get all this times by class name and put in an array, and then do the comparison

Re: Simple date function

Posted: Thu Mar 11, 2010 10:09 am
by pickle
Sounds about right. If you can't post your PHP code, I can't help you convert it to Javascript. Do some investigation into the Javascript Date() object & you might be able to figure it out.