Jump to content

[SOLVED] convert date format


robert_gsfame

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
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

Link to comment
Share on other sites

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??)

     

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.