SitePoint Sponsor

User Tag List

Results 1 to 24 of 24
  1. #1
    The Hiding One lynlimz's Avatar
    Join Date
    Jul 2000
    Location
    Singapore
    Posts
    2,103
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Getting Current Date

    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

  2. #2
    SitePoint Member atem451's Avatar
    Join Date
    May 2001
    Location
    Berlin
    Posts
    24
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    date-function

    Just use the date-function:

    PHP Code:
    echo date("d/m/Y"); 
    Footbag: Spread the Spirit

  3. #3
    SitePoint Addict kunal's Avatar
    Join Date
    Oct 2000
    Posts
    307
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    lynlimz.... i suggest you take a look at the php.net website manual... its a great help when your starting out plus, it will be fast
    i dunno...

  4. #4
    The Hiding One lynlimz's Avatar
    Join Date
    Jul 2000
    Location
    Singapore
    Posts
    2,103
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: date-function

    Originally posted by atem451
    Just use the date-function:

    PHP Code:
    echo date("d/m/Y"); 
    hmm..thats all?
    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

  5. #5
    SitePoint Addict kunal's Avatar
    Join Date
    Oct 2000
    Posts
    307
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $date = date("d/m/Y"); would work fine
    i dunno...

  6. #6
    The Hiding One lynlimz's Avatar
    Join Date
    Jul 2000
    Location
    Singapore
    Posts
    2,103
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thank you!
    "Imagination is more important than knowledge. Knowledge is limited. Imagination encircles the world."
    -- Albert Einstein

  7. #7
    The Hiding One lynlimz's Avatar
    Join Date
    Jul 2000
    Location
    Singapore
    Posts
    2,103
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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

  8. #8
    Victory shall be mine tubedogg's Avatar
    Join Date
    Mar 2001
    Location
    Medina, OH
    Posts
    440
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Not sure I understand? 'filemtime' format?
    Kevin

  9. #9
    The Hiding One lynlimz's Avatar
    Join Date
    Jul 2000
    Location
    Singapore
    Posts
    2,103
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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

  10. #10
    Victory shall be mine tubedogg's Avatar
    Join Date
    Mar 2001
    Location
    Medina, OH
    Posts
    440
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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

  11. #11
    The Hiding One lynlimz's Avatar
    Join Date
    Jul 2000
    Location
    Singapore
    Posts
    2,103
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    wow! cool! thanks tube!
    i'll try it tonight.
    "Imagination is more important than knowledge. Knowledge is limited. Imagination encircles the world."
    -- Albert Einstein

  12. #12
    The Hiding One lynlimz's Avatar
    Join Date
    Jul 2000
    Location
    Singapore
    Posts
    2,103
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $servertime date("U","time()"); 
    tubedogg, the above code returns a 0 for me =(.
    "Imagination is more important than knowledge. Knowledge is limited. Imagination encircles the world."
    -- Albert Einstein

  13. #13
    SitePoint Member atem451's Avatar
    Join Date
    May 2001
    Location
    Berlin
    Posts
    24
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    leave the time() ..

    Just leave the time() away.
    When you use
    PHP Code:
    date("U"
    wihtout a second argument, the current servertime will be used..
    Footbag: Spread the Spirit

  14. #14
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  15. #15
    The Hiding One lynlimz's Avatar
    Join Date
    Jul 2000
    Location
    Singapore
    Posts
    2,103
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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

  16. #16
    Victory shall be mine tubedogg's Avatar
    Join Date
    Mar 2001
    Location
    Medina, OH
    Posts
    440
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ahem...oops I forget the semi-colon, my apologies. other than it would have worked tho...but freddy is also right, his way is much cleaner
    Kevin

  17. #17
    SitePoint Wizard Defender1's Avatar
    Join Date
    Apr 2001
    Location
    My Computer
    Posts
    2,808
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    can someone tell me how to return the date so it looks like this:

    Thursday, June 14th 2001
    Defender's Designs
    I'm Getting Married!

    Not-so-patiently awaiting Harry Potter Book 7 *sigh*

  18. #18
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  19. #19
    SitePoint Wizard Defender1's Avatar
    Join Date
    Apr 2001
    Location
    My Computer
    Posts
    2,808
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.
    Defender's Designs
    I'm Getting Married!

    Not-so-patiently awaiting Harry Potter Book 7 *sigh*

  20. #20
    SitePoint Member
    Join Date
    Jun 2001
    Location
    PA
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.
    I'd really encourage reading the documentation:
    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

  21. #21
    The Hiding One lynlimz's Avatar
    Join Date
    Jul 2000
    Location
    Singapore
    Posts
    2,103
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    let me pass on my php function which was developed with the help of the same people here. =))

    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;

    to get the current time using a unix timestamp adjusted to your timezone,

    $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

  22. #22
    SitePoint Wizard Defender1's Avatar
    Join Date
    Apr 2001
    Location
    My Computer
    Posts
    2,808
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.
    Defender's Designs
    I'm Getting Married!

    Not-so-patiently awaiting Harry Potter Book 7 *sigh*

  23. #23
    SitePoint Member
    Join Date
    Jun 2001
    Location
    PA
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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

  24. #24
    SitePoint Wizard Defender1's Avatar
    Join Date
    Apr 2001
    Location
    My Computer
    Posts
    2,808
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.
    Defender's Designs
    I'm Getting Married!

    Not-so-patiently awaiting Harry Potter Book 7 *sigh*


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •