Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display Date only in PHP? [closed]

Tags:

php

datetime

How to display date only(without time) with format (Y:m:d) for table Return Date? When I choose the date in sql, it'll view as picture1(eg: 2012-04-10), after I save and display back it'll view as picture2(eg: Apr 10 2012 12:00:00). I would like to how to display as(eg: 2012-04-10) not display as (eg: Apr 10 2012 12:00:00) in table Return Date. Thanks

Picture 1

enter image description here

Picture 2

enter image description here

under Result.php

$query = "SELECT ....BE.[batch_id],BED.[ReturnDate] 
FROM .... as BE 
INNER JOIN .... as BED
ON BE.[batch_exception_id] = BED.[batch_exception_id]
WHERE BE.[process_date_time] between '$date1' and '$date2'"; 

while ($row = mssql_fetch_assoc($result)) {   
$rDate = $row['ReturnDate'];
$beID = $row['batch_exception_id'];                         
$proc_dt = $row['process_date_time'];
$batchid = $row['batch_id'];
echo "<tr>";
echo "<td>" . $beID . "<input type='hidden' name='beID[$i]' value='$beID'/></td>";
echo "<td>" . $batchid . "<input type='hidden' name='batchid[$i]' value='$batchid'/></td>";
echo "<td>" . $proc_dt . "<input type='hidden' name='procDT[$i]' value='$proc_dt'/></td>";

echo "<td>";
$date="date[".$i."]"; 
echo "<input type='text' name='date[$i]' id='$date' value='$rDate' onclick=\"fPopCalendar('".$date."')\">";
$i++;
echo "</td>";
echo "</tr>";   
}

Under Save.php

//Select database
$selected = mssql_select_db($myDB, $link)or die("Couldn't open database $myDB");

for ($i=0; $i<$tot_rec;$i++) {
$ret_date=trim($arrretDate[$i]);
ECHO "$ret_date<br>";
if (strlen($ret_date)>0) {
$query = "UPDATE .....
SET [ReturnDate] = '$ret_date'
WHERE [batch_exception_id]= '$arrbeID[$i]'";

$result = mssql_query($query);}
}
//execute the SQL query                     
if ($result){   
header("Location:....");}
else{   
echo "Error Save";   
}
like image 212
srahifah Avatar asked Dec 03 '25 09:12

srahifah


2 Answers

You can try this date('Y:m:d', strtotime($date));

like image 83
gmaliar Avatar answered Dec 05 '25 23:12

gmaliar


You can use: strftime("%Y-%m-%d",$date);. Also check this link.

Content from documentation:

strftime — Format a local time/date according to locale settings

Description: string strftime ( string $format [, int $timestamp = time() ] )

%Y  Four digit representation for the year  Example: 2038
%m  Two digit representation of the month   01 (for January) through 12 (for December)
%d  Two-digit day of the month (with leading zeros) 01 to 31
like image 28
Mohamed Hassan Avatar answered Dec 06 '25 00:12

Mohamed Hassan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!