Convert date from PostgreSQL query

garett09

New member
Happy New Year! :-) Simple question maybe - I have a PostgreSQL server which I connect to and get some data including field with date type. So, I receive date as YYYY-MM-DD but I need DD.MM.YY - how to convert it? Thank you for support.
 
Happy New Year! :-) Simple question maybe - I have a PostgreSQL server which I connect to and get some data including field with date type. So, I receive date as YYYY-MM-DD but I need DD.MM.YY - how to convert it? Thank you for support.
With a simple bit of PHP:
PHP:
<?php// Original date in yyyy-mm-dd 
format$odate = "2012-09-12";// Converting the original date to a new format (dd-mm-yyyy)
$newDate = date("d-m-Y", strtotime($odate));// Displaying the new formatted date
echo $newDate."\n";
?>
 
With a simple bit of PHP:
PHP:
<?php// Original date in yyyy-mm-dd
format$odate = "2012-09-12";// Converting the original date to a new format (dd-mm-yyyy)
$newDate = date("d-m-Y", strtotime($odate));// Displaying the new formatted date
echo $newDate."\n";
?>
Thank you but already tried 'to_char' in my SQL-query:
...
$result2 = pg_query($conn,"select main.s_n, employers.employer, to_char(history.date, 'dd.mm.yy') as FormatedDate from main inner join...
...
while ($row2 = pg_fetch_row($result2)) {
$last_date = $row2[2];
$last_owner = $row2[1];
...
So this is what I want :-) In any case - you helped me a lot.
 

Attachments

  • to_char.jpg
    to_char.jpg
    46.1 KB · Views: 2
Thank you but already tried 'to_char' in my SQL-query:
...
$result2 = pg_query($conn,"select main.s_n, employers.employer, to_char(history.date, 'dd.mm.yy') as FormatedDate from main inner join...
...
while ($row2 = pg_fetch_row($result2)) {
$last_date = $row2[2];
$last_owner = $row2[1];
...
So this is what I want :-) In any case - you helped me a lot.
In your display table, just use a simple date format.
date("dd-mm-YY");
 
Back
Top