raven2009 Posted May 10, 2009 Share Posted May 10, 2009 hi all i have a problem with my statements displaying the wrong date it keeps displaying Nov 30, 1999 even though i am doing it different days these are my codes user statement <?php $getUser="select * from transactions where uid='$id' order by date desc"; $getUser=mysql_query($getUser); $users=mysql_num_rows($getUser); while($row=mysql_fetch_array($getUser)) { $idDB=$row['id']; $typeDB=$row['type']; $transactionDB=$row['transaction']; $amountDB=$row['amount']; $dateDB=$row['date']; list($day, $month, $year) = split("-", $dateDB); $dateDB = date('d M, Y', mktime(0, 0, 0, $day, $month, $year)); ?> <tr> <td bordercolor="#C9D4E3" bgcolor="#5E5E5E"><div align="center"><strong><?php echo $typeDB; ?></strong></div></td> <td bordercolor="#C9D4E3" bgcolor="#5E5E5E"><div align="center"><strong><?php echo $dateDB; ?></strong></div></td> <td bordercolor="#C9D4E3" bgcolor="#5E5E5E"><div align="center"><strong><a href="statementfullview.php?tid=<?php echo $idDB; ?> and the form to add statment <?php require_once('../config.php'); if(isset($_POST['addTransaction']) && $_POST['addTransaction']=='addTransaction') { $email=$_POST['email']; $type=$_POST['type']; $date=$_POST['date']; $transaction=$_POST['transaction']; $amount=$_POST['amount']; $info=$_POST['info']; $getUser="select id from users where email='$email'"; $getUser=mysql_query($getUser); while($row=mysql_fetch_array($getUser)) { $uid=$row['id']; } $addTransaction="insert into transactions(id,uid,type,transaction,amount,date,info) values('','$uid','$type','$transaction','$amount','$date','$info')"; //echo $register; $addTransaction=mysql_query($addTransaction); if($addTransaction) { ?> <script language="javascript1.1"> alert('Transaction added successfully!'); </script> <? } else { ?> <script language="javascript1.1"> alert('addTransaction not added! please try again.'); </script> <? } } ?> thanks in advance Link to comment https://forums.phpfreaks.com/topic/157611-problem-with-displaying-correct-date/ Share on other sites More sharing options...
raven2009 Posted May 10, 2009 Author Share Posted May 10, 2009 hi all i have a problem with my statements displaying the wrong date it keeps displaying Nov 30, 1999 even though i am doing it different days these are my codes user statement <?php $getUser="select * from transactions where uid='$id' order by date desc"; $getUser=mysql_query($getUser); $users=mysql_num_rows($getUser); while($row=mysql_fetch_array($getUser)) { $idDB=$row['id']; $typeDB=$row['type']; $transactionDB=$row['transaction']; $amountDB=$row['amount']; $dateDB=$row['date']; list($day, $month, $year) = split("-", $dateDB); $dateDB = date('d M, Y', mktime(0, 0, 0, $day, $month, $year)); ?> <tr> <td bordercolor="#C9D4E3" bgcolor="#5E5E5E"><div align="center"><strong><?php echo $typeDB; ?></strong></div></td> <td bordercolor="#C9D4E3" bgcolor="#5E5E5E"><div align="center"><strong><?php echo $dateDB; ?></strong></div></td> <td bordercolor="#C9D4E3" bgcolor="#5E5E5E"><div align="center"><strong><a href="statementfullview.php?tid=<?php echo $idDB; ?> and the form to add statment <?php require_once('../config.php'); if(isset($_POST['addTransaction']) && $_POST['addTransaction']=='addTransaction') { $email=$_POST['email']; $type=$_POST['type']; $date=$_POST['date']; $transaction=$_POST['transaction']; $amount=$_POST['amount']; $info=$_POST['info']; $getUser="select id from users where email='$email'"; $getUser=mysql_query($getUser); while($row=mysql_fetch_array($getUser)) { $uid=$row['id']; } $addTransaction="insert into transactions(id,uid,type,transaction,amount,date,info) values('','$uid','$type','$transaction','$amount','$date','$info')"; //echo $register; $addTransaction=mysql_query($addTransaction); if($addTransaction) { ?> <script language="javascript1.1"> alert('Transaction added successfully!'); </script> <? } else { ?> <script language="javascript1.1"> alert('addTransaction not added! please try again.'); </script> <? } } ?> thanks in advance seems there isnt a problem with the code the date format thats the problem im in the uk so my date is displayed dd/mm/yyyy and the database wants me to add it as yyyy/mm/dd strange! lol ??? Link to comment https://forums.phpfreaks.com/topic/157611-problem-with-displaying-correct-date/#findComment-831081 Share on other sites More sharing options...
thebadbad Posted May 10, 2009 Share Posted May 10, 2009 What format is $dateDB in from the database? Link to comment https://forums.phpfreaks.com/topic/157611-problem-with-displaying-correct-date/#findComment-831088 Share on other sites More sharing options...
thebadbad Posted May 10, 2009 Share Posted May 10, 2009 If it's in dd-mm-yyyy format (like your code suggests) then just swap $day with $month in your mktime() function. Link to comment https://forums.phpfreaks.com/topic/157611-problem-with-displaying-correct-date/#findComment-831092 Share on other sites More sharing options...
Ken2k7 Posted May 10, 2009 Share Posted May 10, 2009 Try replacing this line $dateDB = date('d M, Y', mktime(0, 0, 0, $day, $month, $year)); With: $dateDB = $day . ' ' . $month . ' ' . $year; Link to comment https://forums.phpfreaks.com/topic/157611-problem-with-displaying-correct-date/#findComment-831104 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.