5 Replies - 865 Views - Last Post: 27 April 2011 - 06:14 AM

#1 teahou  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 223
  • Joined: 01-April 11

Should I create date function with JS or PHP

Posted 26 April 2011 - 01:38 PM

I am creating a form with a date field. i want the date field to autofill onload. The form will then be submitted to a database. My question then, is should I auto fill the date with JS from the users computer, or with PHP from the server that contains the DB, where the report will be stored?

If my question makes no sense, let me know because i am still pretty new to web coding.

Thank you.
Is This A Good Question/Topic? 0
  • +

Replies To: Should I create date function with JS or PHP

#2 BetaWar  Icon User is offline

  • #include "soul.h"
  • member icon

Reputation: 1199
  • View blog
  • Posts: 7,309
  • Joined: 07-September 06

Re: Should I create date function with JS or PHP

Posted 26 April 2011 - 01:50 PM

Well, it depends. What is the purpose of this date? and what is it used for on the page?
Was This Post Helpful? 0
  • +
  • -

#3 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3577
  • View blog
  • Posts: 10,442
  • Joined: 08-June 10

Re: Should I create date function with JS or PHP

Posted 26 April 2011 - 01:58 PM

always bear in mind that JS may be disabled, so at least PHP will have to do a check on the input.
Was This Post Helpful? 0
  • +
  • -

#4 Prototypical  Icon User is offline

  • D.I.C Head

Reputation: 39
  • View blog
  • Posts: 137
  • Joined: 20-April 11

Re: Should I create date function with JS or PHP

Posted 26 April 2011 - 02:00 PM

If the form has a date field, then I am assuming that they have the option of entering a date ?

So that would seem to suggest that the client's date is what you want.

This really comes down to the requirements of your application though. What is the date used for ? Is the intention to be the date of the client? or is it important for it to be the date of the server.

For example. User is in California, server is in New York. User is 3 hours behind the server.

If the date is essential in deciding if the order should be placed by a deadline EST(New York Time zone), then that date saved better be based on the server. Right ?

In general though, if you want all data on the server to be consistent -- you should be using server time and converting to the user's time zone on the client side if appropriate.

This post has been edited by Prototypical: 26 April 2011 - 02:01 PM

Was This Post Helpful? 2
  • +
  • -

#5 teahou  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 223
  • Joined: 01-April 11

Re: Should I create date function with JS or PHP

Posted 26 April 2011 - 09:38 PM

Thinking about it, i decided to create a date function in js. This is just local info being stored on a local server, so even if the times are not 100% sync'd, I think it will be close enough. Thank you all.
Was This Post Helpful? 0
  • +
  • -

#6 codeprada  Icon User is offline

  • Changed Man With Different Priorities
  • member icon

Reputation: 948
  • View blog
  • Posts: 2,357
  • Joined: 15-February 11

Re: Should I create date function with JS or PHP

Posted 27 April 2011 - 06:14 AM

View PostPrototypical, on 26 April 2011 - 05:00 PM, said:

...
In general though, if you want all data on the server to be consistent -- you should be using server time and converting to the user's time zone on the client side if appropriate.


The client side date won't always be right and you as a programmer's got no control over that. As the other guys stated it all comes down to what you want to do. Displaying a clock on a user page would be more feasible if you used client side time (sending a request to the server every second for the time is a no no). Other things like login timestamp etc...should use server time.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1