Results 1 to 2 of 2

Thread: mktime() issue

  1. #1
    Join Date
    Jan 2007
    Posts
    58
    Thanks
    11
    Thanked 0 Times in 0 Posts

    Default mktime() issue

    Hello, i got a smalldatetime value on mssql (e.g. 5/25/2008), wich is the date when the user subscribed, and i want to show on the website the subscription expire date. Now in order to do so, i should make something like this:

    $time = explode("/", $dbdate);
    $ftime = date("Y/n/d", mktime(0, 0, 0, $dbdate[0], $dbdate[1]+30, $dbdate[2]));

    But it doesn't work because when i echo $dbdate it shows May 25 2008 instead of 5/25/2008, so, there's a problem with $dbdate[0] since the mkdate function won't work with the value "May".

    Now, is there a way to "convert" the value "May" to "5"?

    Thanks

  2. #2
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    My suggestion is that you switch your format to integer, and you put in the unix timestamp as the value using the time() function

    however to convert a human readable date into unix to use to convert "May" to 5 use the code below

    Code:
    $may = strtotime(human-readable);
    $may = date(m, $may);
    m = 01 thru 12 format (with leading zero)
    n = 1-12 (no leading zero)

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
  •