SQL: can a date ONLY contain month/year info?

Ask a Question related to Dreamweaver AppDev, Design and Development.

  1. #1

    Default SQL: can a date ONLY contain month/year info?

    When using a SQL datetime field, is there a way to store ONLY the month and
    year?

    I have a situation where I need to store both month/year and month/day/year
    data in the same column. Ie, some records will store the full date, some
    will only be storing month/year.

    Can the 'day' portion of date/time be null? Or can anyone think of a better
    way to handle this?

    Worst case, I may just tell the folks that they NEED to use a full
    month/day/year and those that are just tracking month/year will have to deal
    with a default day of '1'

    -Darrel


    darrel Guest

  2. Similar Questions and Discussions

    1. group by month/year
      I have a table that has a column titled ArticleDate. I would like to group an output based only on the month and year. For instance, a link for...
    2. 1210: Date could not be converted to month/day/year format
      Hi, I got this error when downloading a table by "unload" order : 1210: Date could not be converted to month/day/year format It seems that a...
    3. Get Year, Month and the Day
      It works fine but i read the date from a database and i need the year, month and day of this date not the system date. If you know how to seperate...
    4. Show" Last view... Day - Month - Date - Year on page.
      Hello All; I have just added in a JavaScript function that show that Day - Month - Day - Year On my page. This is going for a look of Last...
    5. Sort - Month then day without year
      How's about "Sort" Month / Day without year in birthday date field? Daniel R. Sloan
  3. #2

    Default Re: can a date ONLY contain month/year info?

    Hi,
    No a sql server datetime field must contain day month year and time - if
    you miss out say the time sql server will add midnight. Does it have to a
    datetime field? Why not make it a varchar and stick in month/year and
    day/month/year as needed. If you needed to do something like sort by date
    order you could use a case statement to stick a fictional day as needed and
    then cast the field as datetime

    You could insert say March 2005 (although not 3/2005) into a datetime field
    but sql server will add 1 for the day so you'd end up with 1 March 2005 -
    only trouble is you'd need another column to record whether the user
    actually entered 1st March 2005 or just March 2005, this would be easy
    enough but seems like making work for yourself

    Jon

    "darrel" <notreal@hotmail.com> wrote in message
    news:d224vr$kif$1@forums.macromedia.com...
    > When using a SQL datetime field, is there a way to store ONLY the month
    > and
    > year?
    >
    > I have a situation where I need to store both month/year and
    > month/day/year
    > data in the same column. Ie, some records will store the full date, some
    > will only be storing month/year.
    >
    > Can the 'day' portion of date/time be null? Or can anyone think of a
    > better
    > way to handle this?
    >
    > Worst case, I may just tell the folks that they NEED to use a full
    > month/day/year and those that are just tracking month/year will have to
    > deal
    > with a default day of '1'
    >
    > -Darrel
    >
    >

    Jon Spivey Guest

  4. #3

    Default Re: SQL: can a date ONLY contain month/year info?

    sql is limited in date handling only storing dates as yyyyy-mm-dd, however you
    can format the date when displaying it in a table.
    The syntax varies depending on the server technology used.
    Using php you would display a date field in a table something like this
    <?php echo makeDateTime($row_yourtable['date'], 'M j, Y'); ?>
    this would display the date in the form of Jan 01, 2005
    <?php echo makeDateTime($row_yourtable['date'], 'M, Y'); ?>
    would display the date in the form of
    Jan 2005
    If you require the full month name change the M to F

    Taffydog Guest

  5. #4

    Default Re: can a date ONLY contain month/year info?

    > Hi,
    > No a sql server datetime field must contain day month year and time - if
    > you miss out say the time sql server will add midnight. Does it have to a
    > datetime field? Why not make it a varchar and stick in month/year and
    > day/month/year as needed.
    Hmm...that is an *excellent* point. This field won't ever be used for
    sorting or anything. Well...unless we use it for archiving. I'll have to
    mull that over a bit. ;o)
    > If you needed to do something like sort by date
    > order you could use a case statement to stick a fictional day as needed
    and
    > then cast the field as datetime
    Well, that's what I was thinking...since some dates are m/y, but some are
    m/d/y, that I'd just always have a day in there...it's not really a big deal
    if the day is 'fake'.

    -darrel


    darrel Guest

  6. #5

    Default Re: SQL: can a date ONLY contain month/year info?

    > sql is limited in date handling only storing dates as yyyyy-mm-dd, however
    you
    > can format the date when displaying it in a table.
    Thanks, Taffy!

    -Darrel


    darrel Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139