robert_gsfame Posted September 18, 2009 Share Posted September 18, 2009 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) Quote Link to comment https://forums.phpfreaks.com/topic/174702-solved-convert-date-format/ Share on other sites More sharing options...
mikesta707 Posted September 18, 2009 Share Posted September 18, 2009 $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 Quote Link to comment https://forums.phpfreaks.com/topic/174702-solved-convert-date-format/#findComment-920730 Share on other sites More sharing options...
robert_gsfame Posted September 18, 2009 Author Share Posted September 18, 2009 yup, i've tried what you've said but it didn't work either Just want to tell you that i set up a table's column in VARCHAR format Quote Link to comment https://forums.phpfreaks.com/topic/174702-solved-convert-date-format/#findComment-920749 Share on other sites More sharing options...
mikesta707 Posted September 18, 2009 Share Posted September 18, 2009 what table? where is a table involved in this script? echo both post['month'] and post['year'] and make sure they are populated with the correct data. I just tested this and it worked as indicated on my machine Quote Link to comment https://forums.phpfreaks.com/topic/174702-solved-convert-date-format/#findComment-920752 Share on other sites More sharing options...
knsito Posted September 18, 2009 Share Posted September 18, 2009 You probably should check that month and year are valid data first $tmp = $_POST['month'].' '.$_POST['year']; if (($getnumber2 = strtotime($tmp)) === false) { echo "ERROR: The string ($tmp) is bogus"; } else { //do stuff } Quote Link to comment https://forums.phpfreaks.com/topic/174702-solved-convert-date-format/#findComment-920766 Share on other sites More sharing options...
robert_gsfame Posted September 18, 2009 Author Share Posted September 18, 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??) Quote Link to comment https://forums.phpfreaks.com/topic/174702-solved-convert-date-format/#findComment-920958 Share on other sites More sharing options...
knsito Posted September 18, 2009 Share Posted September 18, 2009 * 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 Quote Link to comment https://forums.phpfreaks.com/topic/174702-solved-convert-date-format/#findComment-920976 Share on other sites More sharing options...
redarrow Posted September 18, 2009 Share Posted September 18, 2009 SET YOU DATABASE SETUP TO VARCHAR IT WILL WORK CAPS WAS ON SORRYdam Quote Link to comment https://forums.phpfreaks.com/topic/174702-solved-convert-date-format/#findComment-920983 Share on other sites More sharing options...
robert_gsfame Posted September 19, 2009 Author Share Posted September 19, 2009 i already set my table's column in varchar format........ hmmmm....what's the problem with the code huh?? How come the result always 01/1970 Quote Link to comment https://forums.phpfreaks.com/topic/174702-solved-convert-date-format/#findComment-920991 Share on other sites More sharing options...
redarrow Posted September 19, 2009 Share Posted September 19, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/174702-solved-convert-date-format/#findComment-920993 Share on other sites More sharing options...
robert_gsfame Posted September 19, 2009 Author Share Posted September 19, 2009 i think i have the correct syntax written Quote Link to comment https://forums.phpfreaks.com/topic/174702-solved-convert-date-format/#findComment-920994 Share on other sites More sharing options...
robert_gsfame Posted September 19, 2009 Author Share Posted September 19, 2009 i think i have the correct syntax written Quote Link to comment https://forums.phpfreaks.com/topic/174702-solved-convert-date-format/#findComment-920995 Share on other sites More sharing options...
redarrow Posted September 19, 2009 Share Posted September 19, 2009 does this work please.. <?php echo date("j F Y", strtotime("1941-12-07")); ?> Quote Link to comment https://forums.phpfreaks.com/topic/174702-solved-convert-date-format/#findComment-920996 Share on other sites More sharing options...
robert_gsfame Posted September 19, 2009 Author Share Posted September 19, 2009 7 December 1941 <---Yeah it works Quote Link to comment https://forums.phpfreaks.com/topic/174702-solved-convert-date-format/#findComment-921000 Share on other sites More sharing options...
robert_gsfame Posted September 19, 2009 Author Share Posted September 19, 2009 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"); Quote Link to comment https://forums.phpfreaks.com/topic/174702-solved-convert-date-format/#findComment-921002 Share on other sites More sharing options...
redarrow Posted September 19, 2009 Share Posted September 19, 2009 so it your date format of strtotime then i guess try pal interesting Quote Link to comment https://forums.phpfreaks.com/topic/174702-solved-convert-date-format/#findComment-921004 Share on other sites More sharing options...
robert_gsfame Posted September 19, 2009 Author Share Posted September 19, 2009 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] ??? Quote Link to comment https://forums.phpfreaks.com/topic/174702-solved-convert-date-format/#findComment-921007 Share on other sites More sharing options...
redarrow Posted September 19, 2009 Share Posted September 19, 2009 try this way then? <?php $done = $_POST['month'].' '.$_POST['year']; $keepyear=date("m/Y", strtotime($done)); echo $keepyear; ?> Quote Link to comment https://forums.phpfreaks.com/topic/174702-solved-convert-date-format/#findComment-921008 Share on other sites More sharing options...
robert_gsfame Posted September 19, 2009 Author Share Posted September 19, 2009 NOT WORKING, I HAVE TRIED THAT BEFORE Quote Link to comment https://forums.phpfreaks.com/topic/174702-solved-convert-date-format/#findComment-921010 Share on other sites More sharing options...
robert_gsfame Posted September 19, 2009 Author Share Posted September 19, 2009 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!! Quote Link to comment https://forums.phpfreaks.com/topic/174702-solved-convert-date-format/#findComment-921016 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.