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

  • SEARCH
  • Home
  • 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 3691034
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T04:06:08+00:00 2026-05-19T04:06:08+00:00

In my PHP app, I get dates from the MySQL database, when I format

  • 0

In my PHP app, I get dates from the MySQL database, when I format them with PHP’s date() command. I want to tidy that up and move it all entirely to the view, rather than the retrieval. But I ran into some problems.

When getting a date from the database, I pass it to the rest of the app after running strtotime() on it, so that the date() functions have something they can work with. Is this a good idea? or am I missing something better and obvious? The dates that I’m dealing with are nearly all in the DATE type, not DATETIME.

So, I get the date, and can use date() to display it on the webpage. But sometimes, I’ll get something from the database solely to insert elsewhere in the database, and having to hunt through the backend to find places that need date() kind of defeats the purpose of separating it out to the view. My retrieval functions helpfully return strtotime($date_from_db), and then I create the new entry into the other table… and all new entries must pass through the validation and preparation functions. And herein lies the problem. I validate and prepare dates by seeing if they strtotime() to something other than 0000-00-00. But I can’t run strtotime() on a timestamp; in the test I ran, if gave me 12/31/1969. So my questions:

  1. Is it possible somehow to run strtotime() on a timestamp?
  2. If not, is there an easy way to know if a variable is a timestamp? So I could simply run date() on it rather than dealing with strtotime()? Apart from seeing if it comes out to 12/31/1969, because I don’t know if I can trust a failure to be consistent. Unless that’s a valid thing to do anyway?
  3. And am I doing this completely wrong?
  • 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-19T04:06:08+00:00Added an answer on May 19, 2026 at 4:06 am

    As a general approach, I’d be very tempted to :

    1. Store date/time values using MySQL’s datetime type, as this will allow you to meaningfully query the data within MySQL without having resort to either using >= “timestampvalueX”, etc.

    2. Keep all “live” date information using within PHP scripts in timestamp format.

    As such, you probably want to aim to store all of the date/time related information in that format as a goal. You can the trivially convert this into a format PHP can use either in the query itself (using UNIX_TIMESTAMP) or by exploding the YYYY-MM-DD HH:MM:SS format and using PHP’s mktime to create a “standard” timestamp. (Although you might want to use checkdate for validation purposes.)

    Getting back to your specific questions:

    1. strotime will fail if a timestamp is passed.

    2. As an interim measure you could write a function that checked if the provided value was a 10 digit integer, and presume that it was a native timestamp if it was. (if(is_int($value) && strlen($value) == 10)...)

    3. It’s a bit of a mess by the sounds of things, so as a reasonably short term goal you should probably try and standardise usage both in MySQL and PHP.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a php app to access a MySQL database, and on a tutorial,
I'm writing my first PHP app that has to directly deal with dates, and
In my (PHP) web app, I have a part of my site that keeps
My app is working from the web side of things. I'd like to get
I'm using the data mapper pattern in a PHP app I'm developing and have
I have a LAMP (PHP) web app which need to interface with programs on
I have a .ini file with sensitive information in my php wab app. I
I have an app using PHP and the PayPal API. The basic way it
I have written a web app in PHP which makes use of Ajax requests
I'm building an app in PHP and I'm using the data mapper pattern for

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.