0

I want to convert D, d.m.y to Y-m-d format i.e

echo $from_date=date('Y-m-d', strtotime(Wed, 09.12.15));

But this give me this result 2016-01-13

https://app.absence.io/#/calendar/absence/new check this link, i want to send the from date in 2016-01-01 format to the database

4 Answers4

4

First of all, ensure that your date string is enclosed in quotations (" or ').

Secondly, "Wed, 09.12.15" is not a valid date format that can be understood by strtotime().

The full list of date formats is listed here.

Ben
  • 8,894
  • 7
  • 44
  • 80
  • https://app.absence.io/#/calendar/absence/new check this link, i want to send the from date in 2016-01-01 format to the database – arif hussain Jan 07 '16 at 15:59
1

You can use DateTime::createFromFormat() to convert a non-standard date/time string into a DateTime object, and subsequently DateTime::format() to create a date/time string in your preferred format.

For example:

<?php

$date = '09.12.15';

$dt = DateTime::createFromFormat('d.m.y', $date);

echo $dt->format('Y-m-d'); // 2015-12-09

Hope this helps :)

Darragh Enright
  • 13,676
  • 7
  • 41
  • 48
0

Source

$date1 = date('D d/m/Y h:i:s A',strtotime('2015-06-01'));

Here's a list of format that you can use (Source)

Day of Month
____________
d   | Numeric, with leading zeros   01–31
j   | Numeric, without leading zeros    1–31
S   | The English suffix for the day of the month   st, nd or th in the 1st, 2nd or 15th.

Weekday
_______
l   | Full name  (lowercase 'L')    Sunday – Saturday
D   | Three letter name Mon – Sun

Month
______
m   | Numeric, with leading zeros   01–12
n   | Numeric, without leading zeros    1–12
F   | Textual full  January – December
M   | Textual three letters Jan - Dec

Year
____
Y   | Numeric, 4 digits Eg., 1999, 2003
y   | Numeric, 2 digits Eg., 99, 03

Time
____
a   | Lowercase am, pm
A   | Uppercase AM, PM
g   | Hour, 12-hour, without leading zeros  1–12
h   | Hour, 12-hour, with leading zeros 01–12
G   | Hour, 24-hour, without leading zeros  0-23
H   | Hour, 24-hour, with leading zeros 00-23
i   | Minutes, with leading zeros   00-59
s   | Seconds, with leading zeros   00-59
T   | Timezone abbreviation Eg., EST, MDT ...
Full Date/Time
c   | ISO 8601  2004-02-12T15:19:21+00:00
r   | RFC 2822  Thu, 21 Dec 2000 16:01:07 +0200
Community
  • 1
  • 1
SamyQc
  • 365
  • 2
  • 10
0

May this is Work

$dob = date("d/m/Y",strtotime('09-12-2015'));

or

 $dob = date("d/m/Y",strtotime($res[$i]['date_from_datebase]));

This will output your date from the database in the format of d/m/Y.

Yagnik Detroja
  • 921
  • 1
  • 7
  • 22