Connecting Tech Pros Worldwide Help | Site Map

Convert getdate() to YYYY/MM/DD?

Newbie
 
Join Date: Jun 2009
Posts: 11
#1: Sep 29 '09
Is any solution to convert "1055901520" to yyyy/mm/dd:

Expand|Select|Wrap|Line Numbers
  1. $date = getdate();
  2. print $date[0]; // return 1055901520
  3.  
TheServant's Avatar
Expert
 
Join Date: Feb 2008
Location: Australia
Posts: 913
#2: Sep 29 '09

re: Convert getdate() to YYYY/MM/DD?


Look here.

You will see that [0] is your timestamp (seconds since unix epoch).
Expand|Select|Wrap|Line Numbers
  1. // To get the year (yyyy) it's
  2. echo $date['year'];
  3. // Month (mm) is:
  4. echo $date['mon'];
  5. // Day (dd) is:
  6. echo $date['mday'];
However, you should really look at the date() function as this is probably what you are after. To do your request would be:
Expand|Select|Wrap|Line Numbers
  1. $today = date("Y/m/d");
  2. echo $today;
With the date() function you can put in a second parameter for inital timestamp if that's what you want. If you do not put an initial timestamp, it takes the current one. time() will get you a current timestamp.

I have tried to tell you other ways to solve your problem, but you can use this if that's all you want:
Expand|Select|Wrap|Line Numbers
  1. $date = date("Y/m/d",getdate());
  2. print $date;
Newbie
 
Join Date: Jun 2009
Posts: 11
#3: Sep 29 '09

re: Convert getdate() to YYYY/MM/DD?


Thank you

But how can i convert timestamp (seconds since unix epoch) to date?
(Converting a number to date)
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,629
#4: Sep 29 '09

re: Convert getdate() to YYYY/MM/DD?


Quote:

Originally Posted by Lagon666 View Post

But how can i convert timestamp (seconds since unix epoch) to date?

previous post, second paragraph.
TheServant's Avatar
Expert
 
Join Date: Feb 2008
Location: Australia
Posts: 913
#5: Sep 29 '09

re: Convert getdate() to YYYY/MM/DD?


Quote:

Originally Posted by TheServant View Post

With the date() function you can put in a second parameter for inital timestamp if that's what you want. If you do not put an initial timestamp, it takes the current one. time() will get you a current timestamp.

I have tried to tell you other ways to solve your problem, but you can use this if that's all you want:

Expand|Select|Wrap|Line Numbers
  1. $date = date("Y/m/d",getdate());
  2. print $date;

If you read the date() documentation you will see the first parameter is output format ("Y/m/d") and the second is your time stamp (1055901520 or getdate() or blank for current)...
Reply