1

Hi I've just started learning about timestamp with an absolute template. In one of the examples it says $date1 = strtotime('2015-06-01'); will output Mon 08/01/2015 but I only get a number 1433113200. What am I doing wrong.

$date1 = strtotime('2015-06-01');
echo $date1;
user3660857
  • 333
  • 3
  • 13

5 Answers5

1

Try like this, the number you get is the unix time stamp of your date. You need to reformat it.

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

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
SamyQc
  • 365
  • 2
  • 10
1

you should pass the date to strtotime function with this format: dd-mm-YY, so your code should be:

$date1 = strtotime('01-06-2015');
echo $date1;
Gouda Elalfy
  • 6,888
  • 1
  • 26
  • 38
1

just have the exact place location of the area you wanted to grab

date_default_timezone_set("Asia/Hong_Kong");
$treg = date("Y-m-d H:i:s");

$time obtained from table below:
-25200|International Date Line (West) GMT-12|
-21600|Midway Island, Samoa GMT-11|
-18000|Hawaii, Honolulu GMT-10|
-14400|Alaska GMT-9|
-10800|Pacific Standard Time, US, Canada GMT-8|
-7200|British Columbia N.E., Santa Fe, Mountain Time GMT-7|
-3600|Central America, Chicago, Guatamala, Mexico City GMT-6|
0|US, Canada, Bogota, Boston, New York GMT-5|
+3600|Canada, Santiago, Atlantic Standard Time GMT-4|
+7200|Brazilia, Buenos Aires, Georgetown, Greenland GMT-3|
+10800|Mid-Atlantic GMT-2|
+14400|Azores, Cape Verde Is., Western Africa Time GMT-1|
+18000|London, Iceland, Ireland, Morocco, Portugal GMT|
+21600|Amsterdam, Berlin, Bern, Madrid, Paris, Rome, GMT+1|
+25200|Athens, Cairo, Cape Town, Finland, Greece, Israel GMT+2|
+28800|Ankara, Aden, Baghdad, Beruit, Kuwait, Moscow GMT+3|
+32400|Abu Dhabi, Baku, Kabul, Tehran, Tbilisi, Volgograd GMT+4|
+36000|Calcutta, Colombo, Islamabad, Madras, New Dehli GMT+5|
+39600|Almaty, Dhakar, Kathmandu, Colombo, Sri Lanka GMT+6|
+43200|Bangkok, Hanoi, Jakarta, Phnom Penh, Australia GMT+7|
+46800|Taipei, Beijing, Hong Kong, Singapore, GMT+8|
+50400|Seoul, Tokyo, Central Australia GMT+9|
+54000|Brisbane, Canberra, Guam, Melbourne, Sydney, GMT+10|
+57600|Magadan, New Caledonia, Solomon Is. GMT+11|
+61200|Auckland, Fiji, Kamchatka, Marshall, Wellington, GMT+12|

$treg will be exact

but to convert the time to a specific format use

$date1 = strtotime('2015-06-01');    
$treg = date("D Y-m-d", strtotime($date1));
  • but i prefer to `$treg = date("Y-m-d H:i:s"); $date1 = date("D Y-m-d", strtotime($treg));` to get your wanted date and reaarange the Y-m-d to your prefer date arangement – Jeffrey Arzadon Cabang Dec 23 '15 at 06:27
0
$date1 = date("D d/m/Y", strtotime('2015-06-01'));
echo $date1;

You can check the date format at http://php.net/manual/en/function.date.php

Neobugu
  • 333
  • 6
  • 15
0

if you want output in this format Mon 08/01/2015.This is what you need to do

echo date('D m/d/Y',strtotime('2015-06-01'));

Refer:date php

Sourabh Agrawal
  • 856
  • 10
  • 22