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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T22:33:21+00:00 2026-06-06T22:33:21+00:00

My code $time = Tuesday, 26 June 2012; //str_replace(‘,’,”,$time);<–this also doesn’t work. $a =

  • 0

My code

$time = "Tuesday, 26 June 2012";
//str_replace(',','',$time);<--this also doesn't work.
$a = strptime($time, "%l, %j %F %Y");
$stmp = mktime(0,0,0,$a['tm_mon'],$a['tm_mday'],$a['tm_year'],0);
$from_stmp = date("l, j F Y H:i:s", $stmp);
echo $from_stmp; //Tuesday, 30 November 1999 00:00:00

Now i know there is a more elegant way, that actually works:

$time = "Tuesday, 26 June 2012";
$stmp = strtotime($time);
$from_stmp = date("l, j F Y H:i:s", $stmp);
echo $from_stmp;//Tuesday, 26 June 2012 00:00:00

But what’s wrong with the first version? I’m just curious.

  • 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-06-06T22:33:22+00:00Added an answer on June 6, 2026 at 10:33 pm

    Problem #1

    $a = strptime(time, "%l, %j %F %Y");
    

    You wrote time; it should be $time.

    Problem #2

    Your format string is wrong. strptime doesn’t use the same format strings as date, just with percentage signs in front; it has its own set. Your format string should look like this:

    $a = strptime($time, "%A, %e %B %Y");
    

    Problem #3

    • strptime returns a number of years since 1900. You need to add 1900.
    • strptime returns a month from 0 to 11. You need to add 1.

    All summed up

    Here’s your code, fixed:

    <?php
    $time = "Tuesday, 26 June 2012";
    $a = strptime($time, "%A, %e %B %Y");
    
    $stmp = mktime(0, 0, 0, $a['tm_mon'] + 1, $a['tm_mday'], 1900 + $a['tm_year']);
    $from_stmp = date("l, j F Y H:i:s", $stmp);
    echo $from_stmp;
    ?>
    

    Hooray, it works!

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

Sidebar

Related Questions

Modified the code this time the objective to count the line of code was
The following code does not time out in Ruby 1.9.3p194 (2012-04-20) [i386-mingw32]: require 'timeout'
please help me with this code: every time only the else case is executing
I have this trial timer code to time euler solutions in Ruby. $RUNS =
I have this code: time_t tt = time(NULL); tm* currentTime = gmtime(&tt); tm* storedTime
I write this simple line to get random & unique code each time (just
I have some records like this: ID Personel_Code Time --- ------------- ------ 1 0011
In the following code every time button is clicked the alter shows the value
I write hobby code from time to time. The thing is these tools, classes
Here is the code: class Time { public static void printTime (int hour, int

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.