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

Ask A Question

Stats

  • Questions 186k
  • Answers 186k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer This GNUStep page describes one approach Section 4.5: ...The bright… May 12, 2026 at 5:13 pm
  • Editorial Team
    Editorial Team added an answer It's a good product with a lot of functionalities out… May 12, 2026 at 5:13 pm
  • Editorial Team
    Editorial Team added an answer So you have two application fighting about being top most… May 12, 2026 at 5:13 pm

Related Questions

I have 3 kinds of objects: Agency, BusinessUnit and Client (each with their own
Consider: template <typename T> class Base { public: static const bool ZEROFILL = true;
I have a C# application, and I want to run a function which is
We've been discussing about a client-only solution in javascript that provides means for a

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.