0

I have the following string: 2013-03-22

I need to convert that to a UNIX Timestamp.

How do I do this using PHP?

somejkuser
  • 8,856
  • 20
  • 64
  • 130

4 Answers4

6

Use the strtotime function of PHP.

Like

$unixstamp = strtotime("2013-03-22");
Code Lღver
  • 15,573
  • 16
  • 56
  • 75
2

With DateTime class

$dateTime = DateTime::createFromFormat('Y-m-d', '2013-03-22');
$dateTime->setTime(0, 0, 0);
echo $dateTime->getTimestamp();
Macbric
  • 472
  • 4
  • 10
1

Simple:

echo $time = strtotime("2013-03-22");
Bora
  • 10,529
  • 5
  • 43
  • 73
1

Using

strtotime("2013-03-22")

It will convert the date sting into timestamp value.

Manikandan S
  • 902
  • 1
  • 8
  • 18