NYCPHP Meetup

NYPHP.org

[nycphp-talk] displaying dates in php

selyah selyah1 at yahoo.com
Mon Dec 25 09:39:02 EST 2006


thanks for the response,but that command gives me the date from the computer, i need the date that was selected from the pull-down, (unless my code is not cooded properly)
do you have an example of using the date() function with a user defined date pullown?
thanks

Shadab Wadiwala <shadab_w at yahoo.co.in> wrote: Hi ,
                  This information  will surely help you out !!
   
   
          date( )  

  
---------------------------------
            
  


    string date ( string date_format [, int timestamp] )
  
 
  Users like to have their dates in a variety of formats, so PHP lets you convert timestamps into different types of strings using the date( ) function.
  You can send two parameters to date( ), with the second one being optional, as with strtotime(  ). Parameter one is a special string containing formatting codes for how you want the timestamp converted, and parameter two is the timestamp you want to convert. If you do not supply the second parameter, PHP assumes you want to convert the current time.
  Parameter one is tricky: it is a string of letters from a predefined list of 31 possibles. You can use other characters in the string, and these are copied directly into the formatted date. If you are trying to put words into the date format that you do not want to be converted into their date equivalent, you need to escape them with a backslash, \. To make things even more confusing, if your escaped letter is an existing escape sequence, then you need to escape it again!
  The complete list of date format characters is shown in table. Be careful, as they are case-sensitive!
        Table 7-1. Format characters for use in date( )                Format character
    Description
    Example
        a
    Lowercase am/pm
    am or pm
      A
    Uppercase am/pm
    AM or PM
      B
    Swatch Internet Time
    000 to 999
      c
    ISO 8601 date, time, and time zone
    2004-06-18T09:26:55+01:00
      d
    2-digit day of month, leading zeros
    01 to 31
      D
    Day string, three letters
    Mon, Thu, Sat
       F
    Month string, full
    January, August
      g
    12-hour clock hour, no leading zeros
    1 to 12
      G
    24-hour clock hour, no leading zeros
    0 to 23
      h
    12-hour clock hour, leading zeros
    01 to 12
      H
    24-hour clock hour, leading zeros
    00 to 23
      i
    Minutes with leading zeros
    00 to 59
      I
    Is daylight savings time active?
    1 if yes, 0 if no
      j
    Day of month, no leading zeros
     1 to 31
      l
    Day string, full
    Monday, Saturday
      L
    Is it a leap year?
    1 if yes, 0 if no
      m
    Numeric month, leading zeros
    01 to 12
      M
    Short month  string
    Jan, Aug
      n
    Numeric month, no leading zeros
    1 to 12
      O
    Difference from GMT
    200
      r
    RFC-822 formatted date
    Sat, 22 Dec 1979 17:30 +0000
      s
    Seconds, with leading zeros
    00 to 59
      S
    English ordinal suffix for day number
    st, nd, rd, or th
      t
    Number of days in month
    28 to 31
      T
    Time zone for server
    GMT, CET, EST
      U
    Unix Timestamp
    1056150334
      w
    Numeric day of week
    0 (Sunday), 6 (Saturday)
      W
    ISO-8601 week number of year
    30 (30th week of the year)
      y
    Two-digit representation of year
    97, 02
       Y
    Four-digit representation of year
    1997, 2002
      z
    Day of year
    0 to 366
      Z
    Time zone offset in seconds
    -43200 to 43200

  
 
  This first example of date( ) is very basic and prints out the current time in 24-hour clock format:

    print date("H:i");
  
 
  It's possible to mix  the output of date( ) with a text string to get a natural-looking statement, like this:

    print "The day yesterday was " . date("l", time( ) - 86400);
  
 
  Note that on very specific occasions (particularly when daylight savings time kicks in), the above script will be incorrect. If you need absolute precision, either check for DST or subtract a whole day using mktime( ).
  This next example outputs the date in the format of 31st of August 2005. Notice that we have the word of in the date format, and it has been passed through to the output instead of being converted. The reason for this is that lowercase O and lowercase F do not have any formatting purpose in the date function (although this may be changed in the future), so they are just copied straight into output:

    print date("jS of F Y");
  
 
  In the  next example, our date( ) function is embedded between two other strings, which makes for particularly neat output:

    print "My birthday is on a " . date("l", strtotime("22 Dec 2004")) . " this      year.";
  
Please visit http://shadabworld.110mb.com for further contacting me --
   
  Shadab .I. Wadiwala

selyah <selyah1 at yahoo.com> wrote:
  Dear nyphp:
I am very new to php programming and need some assistance relating to displaying to dates using php.
I wrote a script that involves menu pull-downs for dates that should appear into a form as the end result.
I have the form into a table and all of the other td's appear, except the dates.  I get a 0000/00/000 for the date fields.
I did a goggle for  displaying dates in php, but the results are showing me what i have already done.
Could some one please direct me or give a sample code on how I can get the dates to appear in the proper context (not 0000/00/00).  Thank you in advance
_______________________________________________
New York PHP Community Talk Mailing List
http://lists.nyphp.org/mailman/listinfo/talk

NYPHPCon 2006 Presentations Online
http://www.nyphpcon.com

Show Your Participation in New York PHP
http://www.nyphp.org/show_participation.php


Shadab .I. Wadiwala
 Send free SMS to your Friends on Mobile from your Yahoo! Messenger. Download Now! http://messenger.yahoo.com/download.php_______________________________________________
New York PHP Community Talk Mailing List
http://lists.nyphp.org/mailman/listinfo/talk

NYPHPCon 2006 Presentations Online
http://www.nyphpcon.com

Show Your Participation in New York PHP
http://www.nyphp.org/show_participation.php

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nyphp.org/pipermail/talk/attachments/20061225/f665ee65/attachment.html>


More information about the talk mailing list