arn_php Posted August 20, 2010 Share Posted August 20, 2010 I have a query like this: $query = "SELECT class_name, id FROM tbl_classes WHERE FROM_UNIXTIME(class_date, '%d-%m-%Y') = '".date("d-m-Y", mktime(0,0,0,$zi[1], ($j+($i*7))-date("w",mktime(0,0,0,$zi[1],0,$zi[2])),$zi[2]))."' "; This query should retrieve data from the tbl_classes where the date data is in UNIXTIME format. As a sample, a data date of 1287291600 is read as 17-10-2010 (dd-mm-yy) because of the query above. Anyway, now my data date within the MySQL already in a date format of M d, y and not in the UNIXTIME format. The question is, can someone help me change the query above so it would read my current data date now from M d, y to dd-mm-yy? Thanks a lot for anyhelp. Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted August 21, 2010 Share Posted August 21, 2010 I haven't tested this, but change FROM_UNIXTIME to DATE_FORMAT and give it a try. Quote Link to comment Share on other sites More sharing options...
arn_php Posted August 21, 2010 Author Share Posted August 21, 2010 No, I did it before but won't work. This is the complete code, maybe it would give a better thinking: <?php for($j=0;$j<7;$j++){ $query = "SELECT class_name, id FROM tbl_classes WHERE FROM_UNIXTIME(class_date, '%d-%m-%Y') = '".date("d-m-Y", mktime(0,0,0,$zi[1], ($j+($i*7))-date("w",mktime(0,0,0,$zi[1],0,$zi[2])),$zi[2]))."' "; //$result = mysql_query($query, $connection) or die('ERROR :: QUERY'."<br>".$query."<br>".mysql_error()); $result=mysql_query($query); $xx_m = date("m", mktime(0,0,0,$zi[1], ($j+($i*7))-date("w",mktime(0,0,0,$zi[1],0,$zi[2])),$zi[2])); $xx_d = date("d", mktime(0,0,0,$zi[1], ($j+($i*7))-date("w",mktime(0,0,0,$zi[1],0,$zi[2])),$zi[2])); $detail = ''; if($xx_m != $zi[1]){ $class = "customtext2"; $detail = ''; }elseif(($xx_d == date('d'))&&($xx_m == date("m"))){ $class = "td_today"; if(mysql_num_rows($result) > 0){ while($row = mysql_fetch_assoc($result)){ $class = "td_today_ap"; $detail = '<br /><font size="2"><a href="javascript:void(0)" onClick="javascript:window.open(\'open_details.php?date='.date("d-m-Y", mktime(0,0,0,$zi[1], ($j+($i*7))-date("w",mktime(0,0,0,$zi[1],0,$zi[2])),$zi[2])).'\', \'title\', \'width=400, height=300, statusbar=yes, scrollbars=yes\')">'.stripslashes($row['class_name']).'</a></font>'; } } }else{ if(mysql_num_rows($result) > 0){ while($row = mysql_fetch_assoc($result)){ $class = "td_ap"; $detail = '<br /><font size="2"><a href="javascript:void(0)" onClick="javascript:window.open(\'open_details.php?date='.date("d-m-Y", mktime(0,0,0,$zi[1], ($j+($i*7))-date("w",mktime(0,0,0,$zi[1],0,$zi[2])),$zi[2])).'\', \'title\', \'width=600, height=300, statusbar=yes, scrollbars=yes\')">'.stripslashes($row['class_name']).'</a></font>'; } }else{ $class = "tabel"; $detail = ''; } } ?> See, the data date before is in UNIXTIME where by this, it would be converted into this format d-m-Y. Now I got the data date already in a format of M d, Y.. (from OSCommerce), so how could I make this code to read the data date of M d, Y then directly converted into the d-m-Y? Quote Link to comment Share on other sites More sharing options...
arn_php Posted August 21, 2010 Author Share Posted August 21, 2010 Maybe it would be easier if the data date would be capture directly into UNIXTIME when the field is entered with a date in a format of M d, Y. I have this code at the header of the file: $class_date = tep_db_prepare_input($HTTP_POST_VARS['class_date']); But this one of course would capture the entered data as it is. How would the code be when I want it to capture in UNIXTIME? Quote Link to comment 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.