Professional Web Applications Themes

2 digit Date and month format - ASP

Hi, select month_part = datepart(mm,mdate) select year_part = datepart(yyyy,mdate) How do I get '01' for January sqlserver returns 1 for january date is stored in the db as Datetime Ex : 1-31-2004 22:10:334 TIA TS...

  1. #1

    Default 2 digit Date and month format

    Hi,


    select month_part = datepart(mm,mdate)
    select year_part = datepart(yyyy,mdate)

    How do I get '01' for January sqlserver returns 1 for january
    date is stored in the db as Datetime

    Ex : 1-31-2004 22:10:334

    TIA
    TS


    tony Guest

  2. #2

    Default Re: 2 digit Date and month format

    [url]http://www.aspfaq.com/2300[/url]
    [url]http://www.aspfaq.com/2313[/url]
    [url]http://www.aspfaq.com/2460[/url]
    [url]http://www.aspfaq.com/2464[/url]

    --
    Aaron Bertrand
    SQL Server MVP
    [url]http://www.aspfaq.com/[/url]




    "tony" <ddsdfsf.com> wrote in message
    news:uE3S5#u5DHA.2056TK2MSFTNGP10.phx.gbl...
    > Hi,
    >
    >
    > select month_part = datepart(mm,mdate)
    > select year_part = datepart(yyyy,mdate)
    >
    > How do I get '01' for January sqlserver returns 1 for january
    > date is stored in the db as Datetime
    >
    > Ex : 1-31-2004 22:10:334
    >
    > TIA
    > TS
    >
    >

    Aaron Bertrand [MVP] Guest

  3. #3

    Default Re: 2 digit Date and month format

    Thanks Aaron

    I have a simple approach as folloes

    if cast(mdate as int) <10
    mdate = '0' + mdate

    regds
    Tony

    "Aaron Bertrand [MVP]" <aaronTRASHaspfaq.com> wrote in message
    news:#C9rYJv5DHA.2460TK2MSFTNGP09.phx.gbl...
    > [url]http://www.aspfaq.com/2300[/url]
    > [url]http://www.aspfaq.com/2313[/url]
    > [url]http://www.aspfaq.com/2460[/url]
    > [url]http://www.aspfaq.com/2464[/url]
    >
    > --
    > Aaron Bertrand
    > SQL Server MVP
    > [url]http://www.aspfaq.com/[/url]
    >
    >
    >
    >
    > "tony" <ddsdfsf.com> wrote in message
    > news:uE3S5#u5DHA.2056TK2MSFTNGP10.phx.gbl...
    > > Hi,
    > >
    > >
    > > select month_part = datepart(mm,mdate)
    > > select year_part = datepart(yyyy,mdate)
    > >
    > > How do I get '01' for January sqlserver returns 1 for january
    > > date is stored in the db as Datetime
    > >
    > > Ex : 1-31-2004 22:10:334
    > >
    > > TIA
    > > TS
    > >
    > >
    >
    >

    tony Guest

  4. #4

    Default Re: 2 digit Date and month format

    In VBScript,

    mdate= Right('0' + mdate, 2)

    is the most efficient soln I have found...

    You could probably do something similar in SQL, but I havent checked.

    Chris


    "tony" <ddsdfsf.com> wrote in message
    news:%2309pIov5DHA.2056TK2MSFTNGP10.phx.gbl...
    > Thanks Aaron
    >
    > I have a simple approach as folloes
    >
    > if cast(mdate as int) <10
    > mdate = '0' + mdate
    >
    > regds
    > Tony
    >
    > "Aaron Bertrand [MVP]" <aaronTRASHaspfaq.com> wrote in message
    > news:#C9rYJv5DHA.2460TK2MSFTNGP09.phx.gbl...
    > > [url]http://www.aspfaq.com/2300[/url]
    > > [url]http://www.aspfaq.com/2313[/url]
    > > [url]http://www.aspfaq.com/2460[/url]
    > > [url]http://www.aspfaq.com/2464[/url]
    > >
    > > --
    > > Aaron Bertrand
    > > SQL Server MVP
    > > [url]http://www.aspfaq.com/[/url]
    > >
    > >
    > >
    > >
    > > "tony" <ddsdfsf.com> wrote in message
    > > news:uE3S5#u5DHA.2056TK2MSFTNGP10.phx.gbl...
    > > > Hi,
    > > >
    > > >
    > > > select month_part = datepart(mm,mdate)
    > > > select year_part = datepart(yyyy,mdate)
    > > >
    > > > How do I get '01' for January sqlserver returns 1 for january
    > > > date is stored in the db as Datetime
    > > >
    > > > Ex : 1-31-2004 22:10:334
    > > >
    > > > TIA
    > > > TS
    > > >
    > > >
    > >
    > >
    >
    >

    CJM Guest

Similar Threads

  1. Start and end date of month
    By ccnorris in forum Coldfusion - Advanced Techniques
    Replies: 4
    Last Post: July 19th, 08:46 PM
  2. Query distinct month and date
    By LKnomad in forum Dreamweaver AppDev
    Replies: 0
    Last Post: April 12th, 08:32 PM
  3. Last Date of previous month
    By navdeep virk in forum Informix
    Replies: 9
    Last Post: November 11th, 02:47 PM
  4. Replies: 2
    Last Post: October 9th, 07:37 PM
  5. converting date into database date format(newbie)
    By Binay Agarwal in forum PHP Development
    Replies: 2
    Last Post: August 29th, 01:09 PM

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
  •  

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