Question

I'm working on a restaurant site and I have specific ordering hours. How do I compare a preset time-range with the current visitor's time?

Also I need to set this preset time-range through a form.

Thanks

edit:

I tried to explode the date numbers multiply them and compare but I'm not sure how reliable it is. Other than this I can't ask for the hours, I need to get them with javascript.

Also more exactly I need to let the client change the ordering hours in future.

edit 2: Can't I just compare times in php, a preset time-range with the current time and ditch the JavaScript?

Was it helpful?

Solution

You can always manipulate [Unix]timestamps in PHP comfortably. Take a look at PHP's strtotime() function.

You should be able to use it in a way that suits your current needs!

OTHER TIPS

When you get the DateTime object, in most languages, you can get it with the timezone offset. In Javascript you can use the UTC date to compare items.

Check this out MDN DateTime

Be sure that the full DateTime object with timezone offset is given, should that be from PHP to JavaScript or other way round.

I also recommend that the final check be done on server side (i.e.: in PHP)

Javascript method Date.getTime() return timestamp value in milliseconds, php time() in seconds, you can reduce both values to second and compare them. Are your clients share same Time Zone?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top