Simple date function

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
klevis miho
Forum Contributor
Posts: 413
Joined: Wed Oct 29, 2008 2:59 pm
Location: Albania
Contact:

Simple date function

Post 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.
klevis miho
Forum Contributor
Posts: 413
Joined: Wed Oct 29, 2008 2:59 pm
Location: Albania
Contact:

Re: Simple date function

Post 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())?>';
}
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Simple date function

Post 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)
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
klevis miho
Forum Contributor
Posts: 413
Joined: Wed Oct 29, 2008 2:59 pm
Location: Albania
Contact:

Re: Simple date function

Post 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.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Simple date function

Post by pickle »

Post your PHP code.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
klevis miho
Forum Contributor
Posts: 413
Joined: Wed Oct 29, 2008 2:59 pm
Location: Albania
Contact:

Re: Simple date function

Post 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
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Simple date function

Post 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.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply