Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

210
Views
Getting the real time and date in PHP

i am creating a webpage and i have a form inside of it. In one of my input box i want to set the current date automatically without the user inputting it. I am using the getDate() function of PHP but the problem is that people can change the date by changing their system date and time....

I want the real date and time.

$mydate=getdate(date("U"));
$date = "$mydate[weekday], $mydate[month] $mydate[mday], $mydate[year]";
<input value='$date'>

Help Guys

about 4 years ago · Santiago Trujillo
3 answers
Answer question

0

PHP date() function gets time from your system. So that a user can change his system time and data will have that time.

A solution would be, have a Timestamp field in your database table (I'm assuming that you are going to save the form data in a database) and that will take the time from the server, where the database is hosted.

The user can't change the server's time, so that a correct time will be updated.

about 4 years ago · Santiago Trujillo Report

0

You can use date() function to set current date and time automatically.
For example

 <?php echo '<input type=text value="' . date("d F Y H:i:s") . '" readonly/>';?>

d : Day of the month, 2 digits with leading zeros (01-31)
F: A full textual representation of a month, such as January or March
Y: full numeric representation of a year, 4 digits (2017)
H: 24-hour format of an hour with leading zeros (00 through 23)
i: Minutes with leading zeros (00 to 59)
s:Seconds, with leading zeros (00 to 59)

about 4 years ago · Santiago Trujillo Report

0

The code you have provided sets the dat according to the server's date and time and in not affected by the users' system date and time: The one thing you can add so that the user cannot modify the date is the readonly flag:

$mydate=getdate(date("U"));
$date = "$mydate[weekday], $mydate[month] $mydate[mday], $mydate[year]";

The readonly attribute can be used like so:

<input value="<?php echo $date;?>" readonly="readonly">

OR

<input value="<?php echo $date; ?>" readonly>

If your code is inside php script then:

echo '<input value="'.$date.'" readonly>';
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!