Tuesday, October 7, 2025
HomeLanguagesPHP | date_timestamp_get() Function

PHP | date_timestamp_get() Function

The date_timestamp_get() function is an inbuilt function in PHP which is used to gets the Unix timestamp. This function returns the Unix timestamp representing the date.

Syntax:

  • Procedural style:
    int date_timestamp_get( $object )
  • Object oriented style:
    int DateTime::getTimestamp( void )
    int DateTimeImmutable::getTimestamp( void )
    int DateTimeInterface::getTimestamp( void )

Parameters: This function accepts single parameter $object which is a mandatory. It is used to specify the DateTime object which is returned by the date_create() function. It is used in procedural style only. The object oriented style does not accept any parameter.

Return Value: This function returns the Unix timestamp representing the date.

Below programs illustrate the date_timestamp_get() function in PHP:

Program 1:




<?php
  
// Create DateTime object
$date = date_create();
  
// Display Unix timestamp date
echo date_timestamp_get($date);
?>


Output:

1537162804

Program 2:




<?php
  
// Create DateTime object
$date = new DateTime();
  
// Display Unix timestamp date
echo $date->getTimestamp();
?>


Output:

1537162805

Related Articles:

Reference: http://php.net/manual/en/datetime.gettimestamp.php

RELATED ARTICLES

Most Popular

Dominic
32340 POSTS0 COMMENTS
Milvus
86 POSTS0 COMMENTS
Nango Kala
6708 POSTS0 COMMENTS
Nicole Veronica
11872 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11936 POSTS0 COMMENTS
Shaida Kate Naidoo
6829 POSTS0 COMMENTS
Ted Musemwa
7090 POSTS0 COMMENTS
Thapelo Manthata
6780 POSTS0 COMMENTS
Umr Jansen
6784 POSTS0 COMMENTS