Convert date format in PHP to unix

php date format
strtotime
unix timestamp converter
php unix timestamp to date
php datetime::format
php string to date
strtotime to date in php
php strtotime timezone

I have my date in the following format:

01-02-2019

and I need to get it into the following format:

2019-02-01T00:00:00.000

Is it strtotime I need? I find that a bit confusing to use.

strtotime("01-02-2019");

Thank you for your help.

As @Vidal said, it's look like ISO 8601 but it's a bit different on your example. If this is the exact result you need, here's how:

echo \DateTime::createFromFormat('d-m-Y','01-02-2019')->format('Y-m-d\TH:i:s.v');

will display : 2019-02-01T17:38:33.000

More about the format parameters: http://php.net/manual/en/function.date.php

Edit: I would recommend Vidal answer if this exact format is not mandatory since it's respecting an ISO norme.

strtotime - Manual, etc. How do I convert these to a Unix timestamp. Note that in most cases, this will be in the format of dd mm yyyy� The date_format() function returns a date formatted according to the specified format. Note: This function does not use locales (all output is in English). Tip: Also look at the date() function, which formats a local date/time.

I think the format you want is ISO 8601.

Here the php code.

<?php

$unixTimestamp = date("c", strtotime('01-02-2019'));

?>

PHP: convert date string to Unix timestamp, The strtotime() function parses an English textual datetime into a Unix timestamp (the number of seconds since January 1 1970 00:00:00 GMT). Note: If the year is specified in a two-digit format, values between 0-69 are mapped to 2000-2069 and values between 70-100 are mapped to 1970-2000. Complete list of format options Convert from human-readable date to epoch in PHP. There are many options: 1. Using 'strtotime': strtotime parses most English language date texts to epoch/Unix Time.

As Vidal said in their answer, I think the ISO 8601 standard is what you're after.

I personally prefer the OOP approach, and would recommend always using PHP's DateTime() class over strtotime(), but either will do what you're looking for.

To do the same formatting with DateTime, simply instantiate the DateTime object, and format it as you would with strtotime() like so:

// Build a date object
$myDate = new DateTime('01-02-2019');

// Format and display in the ISO 8601 standard using
// the 'c' format option.
echo $date->format('c');

The magic here is in the 'c' format string, which represents the ISO 8601 constant available to the DateTime class.

More info on DateTimeInterface constants

PHP strtotime() Function, Create a Date From a String With strtotime() The PHP strtotime() function is used to convert a human readable date string into a Unix timestamp (the number of seconds since January 1 1970 00:00:00 GMT). @SobinAugustine et al: strtotime() will convert the date string to a "Unix timestamp (the number of seconds since January 1 1970 00:00:00 UTC)", a format date() can understand and then convert from. So this will not work with a timestamp before 1970. – Samuel Lindblom Jan 30 '14 at 7:12

You can do this way if you want to convert it to another format

<?php
// Create a new DateTime object
echo date('Y-m-d\TH:i:s.v',strtotime('01-02-2019'));
?>

OR

<?php
// Create a new DateTime object
$date = DateTime::createFromFormat('d-m-Y', '01-02-2019');
echo $date->format('Y-m-d\TH:i:s.v');
?>

DEMO1: https://3v4l.org/IlCur

DEMO2: https://3v4l.org/6CMKT

PHP Date and Time, In this video tutorial, I'm going to show you how you can change the date format using date Duration: 4:47 Posted: 1 Apr 2019 The Unix epoch (or Unix time or POSIX time or Unix timestamp) is the number of seconds that have elapsed since January 1, 1970 (midnight UTC/GMT), not counting leap seconds (in ISO 8601: 1970-01-01T00:00:00Z). Literally speaking the epoch is Unix time 0 (midnight 1/1/1970), but 'epoch' is often used as a synonym for Unix time.

PHP Epoch Converter and Date/Time Routines, You can first use the PHP strtotime() function to convert any textual datetime into Unix timestamp, then simply use the PHP date() function to convert this� The epoch time or unix timestamp is used to describe a point in time. It is a number of seconds between date time which elapsed since 00:00:00 Thursday, 1 January 1970 at Coordinated Universal Time (UTC).

Convert php date format using date() and strtotime(), This function returns a string formatted according to the given format string Convert date string to timestamp in Python � How to convert Unix� Microseconds (added in PHP 5.2.2). Note that date() will always generate 000000 since it takes an integer parameter, whereas DateTime::format() does support microseconds if DateTime was created with microseconds. Example: 654321: v: Milliseconds (added in PHP 7.0.0). Same note applies as for u

How to Convert a Date from yyyy-mm-dd to dd-mm-yyyy Format in PHP, How to Convert PHP Timestamp to Date Format with example, unix timestamp to date time format,php get current timestamp,php timestamp now to date,php� Dear Expert How to convert date in format of YYYY-MM-DD HH:MM:SS to unix format using a script or command if avaliable Example Code : "2011-05-15 18:00:00" is converted to 1330970400

Comments
  • Possible duplicate of Convert one date format into another in PHP
  • strtotime returns a unix timestamp which, despite the title of your question, is not what you're looking for.
  • @FedericoklezCulloca what is this format called?
  • I'm not sure it has a proper name, but it looks like some form of Internet date format as described in rfc 3339
  • Note: I'm saying it doesn't have a name because I'm not 100% sure it conforms to ISO 8601 (I'm not sure the timezone is mandatory and I'm not gonna read the whole standard to find out), which is probably the closest you could get to what you want.