Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 303459
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T07:11:25+00:00 2026-05-12T07:11:25+00:00

This is a double question in terms of front end usability and PHP DATE_TIME

  • 0

This is a double question in terms of front end usability and PHP DATE_TIME validation.

I am working on a site for a client who would like to add the date he finished a project (so the projects can be listed in that order). He will be the only one using the admin interface, so I would like it to be as simple as possible.

I am storing the dates as DATE_TIME in a SQLite db.

I would like to require the client enter at least the year and month, with the option to add day, hour, minute, second to the DATE_TIME. If these are not set they will default to the smallest number.

I thought the best way and easiest to do this was making a single input form taking the input(left) and making the result(right). Making him use xxxx/xx/xx/xx/xx/xx as the format.

2009/08       = 2009-08-01 00:00:01
2009/08/01    = 2009-08-01 00:00:01
2009/08/01/05 = 2009-08-01 05:00:01

(adding one second as default otherwise it will be the day before)

I tried first by exploding the input into an array and validating each date section with regex. it got messy real fast and I can’t figure out how to validate the proper ranges, say, /[1980-2009]/ or /[01-12]/ (that doesn’t work like I expected). Also /[(0-9){2}]/ isn’t going to work for the month obviously.

Another option is making each date section a separate select field. Making each field after month optional. But that gets messy in the html output, also given that each month doesn’t have 31 days, I would need some javascript to change the day field depending on what month is selected. That’s too much. It also seems a lot easier and faster to use a single field.

What do you guys suggest is the best way to input and validate custom datetimes?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T07:11:26+00:00Added an answer on May 12, 2026 at 7:11 am

    I would reccomend calling strtotime() on the date, that way he can enter a variety of date formats, including month/year, day/month/year, day/month/year hours:minutes, and year-month-day hours:minutes

    If strtotime can’t determine what the date is, it returns false (or -1 in older versions of PHP, check your manual). SO your general code would be:

    1. Run input through stripslashes (if needed) and strtotime
    2. Check if value is === false. If so, display error
    3. Otherwise, format the time as yor database expects is using date()
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is not a duplicate of Implementing the copy constructor in terms of operator=
I need to write a method where the parameter accepts an integer (n in
I have the following problem. Let's take the input (wikitext) ======hello((my first program)) world======
I am seeing too frequently not null primary key in scripts creating tables in
When creating classes for immutable objects immutable meaning that state of instances can not
At first I thought that hash hack is a requirement, however judging from the
Is it possible to write the complete C++ standard library (including STL of course,
I have the following scenario: Due to an unfortunate legacy database, I have some
Let's consider python (3.x) scripts: main.py: from test.team import team from test.user import user
The intent is to create a set of web services that people can reuse.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.