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,656
  • 19
  • 58
  • 122

4 Answers4

6

Use the strtotime function of PHP.

Like

$unixstamp = strtotime("2013-03-22");
Code Lღver
  • 15,434
  • 16
  • 54
  • 74
2

With DateTime class

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

Simple:

echo $time = strtotime("2013-03-22");
Bora
  • 10,182
  • 5
  • 41
  • 70
1

Using

strtotime("2013-03-22")

It will convert the date sting into timestamp value.

Manikandan S
  • 842
  • 1
  • 8
  • 17