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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T21:01:24+00:00 2026-05-30T21:01:24+00:00

I need to add a zero to the date value that is posted as

  • 0

I need to add a zero to the date value that is posted as the MySQL date value will be used as a directory path to show added photos. Currently the directory is saved as 2012-2-5 and the MySQL entry is 2012-02-05.

I have tried the following, however it doesn’t seem to be working:

$dates = array($_POST['photos_year'], $_POST['photos_month'], $_POST['photos_day']);
    foreach($dates as $date) {
    if (strlen($date) == 1) {
        $date = '0' . $date;
    }
    }
$photos->date = $dates[0] . "-" . $dates[1] . "-" . $dates[2];

I am using a for loop to create the date form, it might be easier for me to edit this however I haven’t had any success:

<select name="photos_month"  id="photos_month" tabindex="3">
    <option value ="">- Month -</option>
    <?php 
    for($date=01;$date<=12;$date++) {
        if (isset($photos) && $date==$month) {
            echo "<option value='".$date."' selected='selected'>".$date."</option>";
        } else {
            echo "<option value='".$date."'>".$date."</option>";
        }
    }
    ?>
</select>
  • 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-30T21:01:30+00:00Added an answer on May 30, 2026 at 9:01 pm

    You need to update the foreach to be

    foreach ($dates as &$date)
    

    Currently, $date is a new symbol and will not overwrite the value. That should fix it, but it may be nice to have the correct strings in the options too. You can use str_pad to do that.

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

Sidebar

Related Questions

Is there a way to add a leading zero to a date that is
Sadly, I have a legacy PHP4 system that I continuously need to add features
I need to run a program that will have a similar output both on
I need to write a javascript program that will ask the user to enter
I need add a new user group for mediawiki. The new group has more
need to add a 2nd css stylesheet to a page. do i add a
I need to add a web part zone to a wiki page. I'm opening
I need to add DVD writing functionality to an application I'm working on. However
I need to add role based permissions to my Rails application, and am wondering
I need to add a specific column if it does not exist. I have

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.