Jump to content

date


arn_php

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/211287-date/
Share on other sites

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?

Link to comment
https://forums.phpfreaks.com/topic/211287-date/#findComment-1102019
Share on other sites

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?

Link to comment
https://forums.phpfreaks.com/topic/211287-date/#findComment-1102032
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.