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 7557455
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T12:08:10+00:00 2026-05-30T12:08:10+00:00

I’m trying to get my head round someone else’s code which they’ve written for

  • 0

I’m trying to get my head round someone else’s code which they’ve written for handling the dates of when news stories are published. The problem has come up because they are using this line –

$date = strtotime("midnight", strtotime($dateString));

to process a date selected using a jquery calendar widget. This works fine for future dates, but when you try to use a date which is in the previous calendar year, it uses the current year instead. I think this is due to “midnight” finding the closest instance of the selected day and month.

I could remove the “midnight”, but I’m not sure what the repercussions of this would be – is there a reason that the midnight could be there?

EDIT: this is the full block of code which handles the date. The date contains the time, which allows the user to publish an item at a specific time.

            $array['display_date'] = '24 October, 2011 17:30';
            $string = $array['display_date'];
            $dateString = substr($string, 0, -5);

            $timeArray = explode(':', substr($string, -5));
            $hours_in_secs = 60 * 60 * $timeArray[0];
            $mins_in_secs = $timeArray[1];
            $date = strtotime("midnight", strtotime($dateString));

            $timestamp = $date + $hours_in_secs + $mins_in_secs;

            //assign timestamp to validation array
            $array['display_date'] = $timestamp;
            echo $array['display_date']; // Output = 1351094430 (Oct 24 2012 17:00:30)
  • 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-30T12:08:12+00:00Added an answer on May 30, 2026 at 12:08 pm

    This really depends on what $dateString contains. Assuming your jQuery widget delivered the time portion as well, your colleague likely wanted to remove the time portion. Compare the following:

    echo date(DATE_ATOM, strtotime('2010-10-01 17:32:00'));
    // 2010-10-01T17:32:00+02:00
    
    echo date(DATE_ATOM, strtotime("midnight", strtotime('2010-10-01 17:32:00')));
    // 2010-10-01T00:00:00+02:00
    

    If your widget doesnt return the time portion, I dont see any reason for setting the date to midnight, because it will be midnight automatically:

    echo date(DATE_ATOM, strtotime('2010-10-01'));
    // 2010-10-01T00:00:00+02:00
    

    Note that all these are dates in the past and they will result in the given year in the past, not the current year like you say. If they do in your code, the cause must be somewhere else.

    Will there be repercussions when you change the code? We cannot know. This is just one line of code and we have no idea of any context. Your unit-tests should tell you when something breaks when you change code.

    EDIT after update

    The codeblock you show makes no sense whatsoever. Ask the guy who wrote it what it is supposed to do. Not only will it falsely return the current year for past years, but it will also give incorrect results for the minutes, e.g.

    24 March, 2010 17:30 will be 2012-03-24T17:00:30+01:00
    

    I assume this was an attempt at turning 24 March, 2010 17:30 into a valid timestamp, which is in a format strtotime does not recognize. But the approach is broken. When you are on PHP5.3 use

    $dt = DateTime::createFromFormat('d F, Y H:i', '24 March, 2010 17:30');
    echo $dt->format(DATE_ATOM); // 2010-03-24T17:30:00+01:00
    

    If you are not on 5.3 yet, go through https://stackoverflow.com/search?q=createFromFormat+php for alternate solutions. There is a couple in there.

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

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I used javascript for loading a picture on my website depending on which small
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a text area in my form which accepts all possible characters from
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka

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.