0

I'm creating an auction site where time and date is inserted in following format:

Auction Date : 08/20/2015 @ 05:30 PM IST

I want to match this time with my user's time and dont want to show auctions which have passed the start date as per users time zone. Assume users may come from different timezones.

Can someone please guide me on this.

Jimmy
  • 93
  • 1
  • 8
  • Js gives client server side date time, php your server date time. With this you can easyly solve your problem. Get your date using php, get the client date using JS then compare them – Hearner Aug 20 '15 at 12:54
  • Do you store the user's timezone separately, perhaps as a TZ identifier; e.g: `Europe/Dublin` or `America\New_York`? – Darragh Enright Aug 20 '15 at 13:04
  • 1
    I'm having a hard time to understand the problem. The auction is either active or unactive, timezone setting can not (should not) affect to that. So all you need is to tell if the auction have started, passed, will start, or whatever in days, hours and/or minutes. (Maybe just skip the passed ones automatically.) Or am I missing something? – ZZ-bb Aug 20 '15 at 13:16
  • @Hearner YES, i understand that concept and thought about that before as well, but i having trouble in converting time from one timezone to another. – Jimmy Aug 20 '15 at 14:14
  • @Darragh Noh, this is the only we are getting from our crawler script. – Jimmy Aug 20 '15 at 14:14
  • You don't have to convert because you see something like `01/25/2015` but this isn't how the program understand it. It understands it as `42029`. Because it's the number of minutes between 1900 to now (something like that) so you easily compare them. Store the script result into a hidden field for example – Hearner Aug 20 '15 at 14:18
  • @ZZ-bb, sorry If i failed to explain my problem, but you got it. For example at present in india its 8 PM and if auction starts at 8 AM CMT, I need to check that auction have not passed the start time. Hope this help. – Jimmy Aug 20 '15 at 14:18
  • What you want to do is to compare date from different timezone so why would you want to convert them ? – Hearner Aug 20 '15 at 14:18
  • @user3406496 - is that format (e.g: `08/20/2015 @ 05:30 PM IST`) all you have? Because if you need to be TZ-aware, you could parse out the Time Zone Abbreviation. Of course you then immediately have a problem because in the example above IST can refer to "India Standard Time", "Irish Standard Time" or "Israel Standard Time". – Darragh Enright Aug 20 '15 at 15:21
  • @Hearner yes you are right, My main goal is comparison, is it possible to find out auction start time is passed out or not according to their timezone. – Jimmy Aug 20 '15 at 19:34
  • So you just insert the starting time in one format, using the timezone setting for all of them (or with the timezone information if you can keep track of things). Then you don't need to worry about user's local time because you only compare the auction starting time to the chosen timezone time (essentially to itself: "Has this time already passed?"). Store for example as UTC and echo it as local time (you of course need to know or guess the user's local time): http://stackoverflow.com/questions/1349280/storing-datetime-as-utc-in-php-mysql – ZZ-bb Aug 21 '15 at 06:32
  • In any case you can simply ignore the user's timezone. If the auction has passed, it has passed. There is no such thing as "in _their timezone_ the auction has not started or passed". – ZZ-bb Aug 21 '15 at 06:34
  • Hi Everybody, We've drop this plan for now, I'm really sorry about this, But you guys helped a lot and I learned loads of new points. Thank you so much, Happy Helping.. :) – Jimmy Aug 21 '15 at 17:11

1 Answers1

1

You would have to storage your user's timezone somewhere for comparisson purposes. This means your user's model (user's specific info in your system) must know about their timezone.

Then in PHP you have the DateTime and DateTimeZone classes to play with it.

To give you an example, and this is in the docs you can instantiate DateTime like this:

$dt = new DateTime("your date string", new DateTimeZone("[timezone_location_string]"));

You can compare DateTime objects with the PHP comparisson operators (<,>,>=,<=,==) which is pretty nice.

And here you have a list of timezones used in PHP for instantiating objects like DateTimeZone():

http://php.net/manual/en/timezones.php

MarkSkayff
  • 1,334
  • 9
  • 14
  • This is a good answer, although unfortunately the OP has since clarified in a comment that they do not have timezone identifiers for individual users, which complicates matters somewhat. – Darragh Enright Aug 20 '15 at 15:17