Jump to content

Recommended Posts

So confusing, what's wrong with this ??

 

<?php

if(isset($_POST['check'])){

$getnumber1="No data";}else{

$getnumber2=date("m",strtotime($_POST['month']))).'/'.$_POST['year'];

echo $getnumber2;

 

?>

And i don't get the month value being read, only the year....

 

(What i want to do is just to change the format from 1 to 01)

Link to comment
https://forums.phpfreaks.com/topic/174702-solved-convert-date-format/
Share on other sites

$getnumber2=date("m/Y",strtotime($_POST['month'].' '.$_POST['year']));

echo $getnumber2;

 

try that, you example didnt really make much sense. you are telling it to convert your string, which may look like

march/2009

 

to the format of a 2 digit representation of a month.

 

the following outputs

$getnumber2=date("m/Y",strtotime("March 2009"));

echo $getnumber2;

03/2009

okay this is the detail of the code...

i have a form

 

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="form1" id="form1">

 

<?php

  <select name="month" id="month">

for($i=1;$i<13;$i++){

echo "<option value=$i>$i</option>";}?>

        </select>

   

          <select name="year" id="year">

        <?php

$annum=date("Y");

for($i=1900;$i<=$annum;$i++){

echo "<option value=$i>$i</option>";}?>

        </select>

      <input type="submit">

 

 

ONCE POST-->

 

$keepyear=date("m/Y", strtotime($_POST['month'].'/'.$_POST['year']));

 

 

THEN RECORD INSERTED INTO MYDATABASE

 

* the problem is occured when i retrieve the record from my table as it always give me the value of  01/1970 although i choose 05/1930

 

* When i keep the record without converting the date using strtotime, i will get the value of 5/1930 which is the correct answer (This means something wrong with the converted string, is that right??)

     

* the problem is occured when i retrieve the record from my table as it always give me the value of  01/1970 although i choose 05/1930

 

Sounds like you have this problem

 

http://us3.php.net/manual/en/function.date.php

However, before PHP 5.1.0 this range was limited from 01-01-1970 to 19-01-2038 on some systems

what php version you got?

 

did you read this link?

 

think off another way froward......

 

 

http://us3.php.net/manual/en/function.date.php

 

 

according to the error you php.ini setup not letting you go back to $annum=date("Y"); 1900 only 1970 onwards.

i got some clue....i think it's because date should be written completely, i mean it should has day, month and year

 

Just change, i try this syntax and it returns wrong value like what i said above

 

echo date(" F Y", strtotime("1941-07");

 

 

so what to do?? i just give 2 list menu for users to choose, one for month and the other for year

 

Do i have to put a day like '1' and inserted into my database, which i have to use explode("/",$date) and take the value only $date[1] and $date[2] ???

 

 

 

Although it sounds a bit complicated and crazy but i use this syntax

 

I put all list menu values for month and year added with '1' just to convert the format of the date into 'd m Y' then i break it using explode then get the value of each array and put it inside my database table

 

In order to have my list menu checked once value is the same with what i have inside the table... i also convert it into 'd n Y' break it using explode and get the value of each array....

 

AND IT'S DONE!! :P

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.