-4

I am creating a delivery system in PHP but cannot get the date to come out as DAY dd/mm/yyyy currently it comes out as yyyy/mm/dd which I understand is the default.

I am using the following code to display the delivery date within the lightbox:

<?php echo $Deliverydate; ?>

After looking around and doing some research I found this alternative:

                    <?php
                    $source =   '2015-05-12';
                    $date = new DateTime($source);
                    echo $date->format('d.m.Y'); // 31.07.2012                  
                    ?>

However as the delivery dates are stored in a MySQL database using the following code I get an error within the lightbox.

$source = '$Deliverydate'; 

This gives me the error:

Fatal error: Uncaught exception 'Exception' with message 'DateTime::__construct(): Failed to parse time string $Deliverydate; at position 0 (<): Unexpected character' in /home4/rylshieldltd/public_html/sandgcrm/getOrder.php:63 Stack trace:

0 /home4/rylshieldltd/public_html/sandgcrm/getOrder.php(63): DateTime->__construct('

/home4/rylshieldltd/public_html/sandgcrm/getOrder.php on line 63

If anyone could help me pull the time through from the database using PHP and also display the correct day for the date selected that'd be greatly appreciated.

Saty
  • 22,443
  • 7
  • 33
  • 51
Crumb
  • 7
  • 4
  • Check the format of the date time string. – Sougata Bose Jul 06 '15 at 11:45
  • 1
    `$source = '$Deliverydate';`.... You realise that this is setting `$source` as a literal value `$Deliverydate` not as the value of variable `$Deliverydate`.... either use double quotes (`"`) or (better yet) don't use quotes at all – Mark Baker Jul 06 '15 at 11:45
  • Spot on @MarkBaker . Beat me to it – mituw16 Jul 06 '15 at 11:46
  • `$source = $Deliverydate;` ? you don't need quotes or your variable will be a string. – Vincent Decaux Jul 06 '15 at 11:46
  • if you're using date('d/m/Y H:m:s') it won't work proprely, I personaly get 15min less than the real time. The best way is to do as the fallowing : ` $sql = date('Y-m-d H:i:s'); echo date('dd/mm/Y', strtotime($sql));` – Hearner Jul 06 '15 at 11:47

1 Answers1

1

Try this :)

$my_var = date("d.m.Y",strtotime($DeliveryDate));
ZelkiN
  • 1,721
  • 1
  • 10
  • 6