Hi,
How do you get the current server's date in the form of DD/MM/YYYY ?
Thanks
| SitePoint Sponsor |





Hi,
How do you get the current server's date in the form of DD/MM/YYYY ?
Thanks
"Imagination is more important than knowledge. Knowledge is limited. Imagination encircles the world."
-- Albert Einstein
Just use the date-function:
PHP Code:echo date("d/m/Y");
Footbag: Spread the Spirit
lynlimz.... i suggest you take a look at the php.net website manual... its a great help when your starting outplus, it will be fast
![]()
i dunno...





hmm..thats all?Originally posted by atem451
Just use the date-function:
PHP Code:echo date("d/m/Y");
i want to assgin the date to $date variable.
so i do it like this?
$date = date("d/m/Y");
?
Cause I need to transfer the date to my php function which converts dates to my specific time zone.
thanks kunal for the tip. lol
"Imagination is more important than knowledge. Knowledge is limited. Imagination encircles the world."
-- Albert Einstein
$date = date("d/m/Y"); would work fine![]()
i dunno...





thank you!
"Imagination is more important than knowledge. Knowledge is limited. Imagination encircles the world."
-- Albert Einstein





Hi,
A little problem.
I need to convert date("d/m/Y"); to filemtime format.
How do I do that? thanks
"Imagination is more important than knowledge. Knowledge is limited. Imagination encircles the world."
-- Albert Einstein



Not sure I understand? 'filemtime' format?
Kevin





i use filemtime to get the last modified of a file.
now..i need to get the server's date to that format. could you help me on that? thank you for your time.
"Imagination is more important than knowledge. Knowledge is limited. Imagination encircles the world."
-- Albert Einstein



Oh I see. It returns a unix timestamp. OK so you want to convert the server time to a unix timestamp. Easy as pie.Just do
$servertime = date("U","time()");
That will take the current time ("time()") and put it in a unix timestamp in the variable $servertime.
Kevin





wow! cool! thanks tube!
i'll try it tonight.
"Imagination is more important than knowledge. Knowledge is limited. Imagination encircles the world."
-- Albert Einstein





tubedogg, the above code returns a 0 for me =(.PHP Code:$servertime = date("U","time()");
"Imagination is more important than knowledge. Knowledge is limited. Imagination encircles the world."
-- Albert Einstein
Just leave the time() away.
When you use
wihtout a second argument, the current servertime will be used..PHP Code:date("U")
Footbag: Spread the Spirit





lynlimz its just time() thats all you need to get the unix timestamp
$servertime = time();
Please don't PM me with questions.
Use the forums, that is what they are here for.





wow!
time(); did the trick! thanks guys for your help once again!
"Imagination is more important than knowledge. Knowledge is limited. Imagination encircles the world."
-- Albert Einstein



ahem...oopsI forget the semi-colon, my apologies. other than it would have worked tho...but freddy is also right, his way is much cleaner
![]()
Kevin





can someone tell me how to return the date so it looks like this:
Thursday, June 14th 2001





What format do you want it in?
www.php.net/date
There is a big list of letters that you can use in date() to get the format you want.
For instance
D //Prints Abbreviated Day ie Mon
l //prints whole day ie Monday
w //prints number of the day of the week. Sun = 0 Sat = 6
Please don't PM me with questions.
Use the forums, that is what they are here for.





thanks, but is there a way to display it in a different time zone? cause apparently, my server say it's already friday.
i want to change it so it displays correctly for EST time zone here in massachusetts.
Last edited by Defender1; Jun 14, 2001 at 17:08.
I'd really encourage reading the documentation:Originally posted by Defender1
thanks, but is there a way to display it in a different time zone? cause apparently, my server say it's already friday.
i want to change it so it displays correctly for EST time zone here in massachusetts.
http://www.php.net/manual/en/ref.datetime.php
Lots of great things to learn there. All I ever learned in PHP was from reading the manual.
To answer your question ... date() is going to use the local time of the server you're on.
To adjust the date, you use the mktime() function. mktime() takes seven parameters, but you can leave each parameter going from right to left. Because the first parameter is the "hour" parameter, you can just do this ...
Say you are 2 hours difference in time from where the server is ...
PHP Code:$hour=date("g"); // the current hour according to the server
$unixtime=mktime($hour-2);
$localtime = date("format-string",$unixtime);
To explain further ...
the "date" function takes two parameters ...
The first one is the format string
The second one is a unixtime
If the second is left blank, the current time is used
the "mktime" function creates a unixdate based upon the parameters it's given.
I wrote the above so it's less confusing to look at. I would normally just do it:
$localtime=date("format",mktime(date("g")-2));
I learned everything above by reading up on all of those functions in the docs.
Adam W.
Web Developer / Columnist
http://www.uscho.com





let me pass on my php function which was developed with the help of the same people here. =))
to get the current time using a unix timestamp adjusted to your timezone,PHP Code:function adj_timezone($moddate) {
$hour = ($hour * 3600);
$newtime = $moddate + 11;
$adj_time = date("d/m/y|g:i:s a", $newtime);
$time = explode("|", $adj_time);
return $time;
}
$unix_timestamp = time();
$timezone = adj_timezone($unix_timestamp);
to get just the format of DD/MM/YY, use $timezone[0]. to get the time and seconds etc. use $timezone[1]
to get both date and time:
$current = "$timezone[0] $timezone[1]"; //note the space
modify '+ 11' in the php function to adjust with accordance to your timezone.
modify 'd/m/y|g:i:s a' to set how the date/time is written.
for example, if you want MM/DD/YYYY, use 'm/d/Y'.
Hope. I'm able to relate what i've learnt from these wonderful guys. =)
"Imagination is more important than knowledge. Knowledge is limited. Imagination encircles the world."
-- Albert Einstein





this is really strange
right now it's 10:54 pm est
the server says:
Friday, June 15th
9:54 pm (timezone unknown)
it's ahead by 24 hours!
so, i used -12 for your snippet and it worked.
now says correct date/time.
Last edited by Defender1; Jun 14, 2001 at 19:17.
Actually, dude, it's currently 9:54 EDT .... not sure what clock you're looking at :-)
Adam W.
Web Developer / Columnist
http://www.uscho.com





yea, i was looking at it wrong.
but my server is suppose to be in florida, so i'm confused why the system is off by 24 hours.
Bookmarks