VB Date functions into ISO format for SQL server

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

  1. #1

    Default VB Date functions into ISO format for SQL server

    Hi everyone,

    I am developing a advertising portal site for villa rentals. In which we
    require to charge for advertising on a 6 or 12 month basis. Each advert has an
    advert end date, which is stored in an SQL database as a shortdatetime, with a
    short date format.

    Someone can add 6 months or 12 to their advert even when the advert end date
    has passed. This part of the coding is fine, no problem. It is however when
    someone pays for the advert in advance which cause a problem. As the advert end
    date needs to be updated by 6 or 12 months from the advert end date in the
    database.

    Now I have all sort of problems with the date function, and therefore have
    converted everything into ISO format. When i need to do is read the date into
    the script, convert it to ISO, add the period to it (i.e. 6 or 12 months) then
    put it into a form hidden field. this is the code thus far....

    ------------------------
    'get new end date
    varAdvertEndDate = (rsProp.Fields.Item("AdvertEndDate").Value)
    varPeriod = request.querystring("period")
    if varAdvertEndDate < Date() then
    if varPeriod = 12 then
    varDay = Day(date)
    varMonth = Month(date)
    varYear = Year(date) + 1
    varNewEndDate = varYear & _
    "-" & Right(Cstr(varMonth + 100),2) & _
    "-" & Right(Cstr(varDay + 100),2)
    end if
    if varPeriod = 6 then
    varDay = Day(date)
    varMonth = Month(date)
    if varMonth = 7 then varMonth = 1
    if varMonth = 8 then varMonth = 2
    if varMonth = 9 then varMonth = 3
    If varMonth = 10 then varMonth = 4
    if varMonth = 11 then varMonth = 5
    if varMonth = 12 then varMonth = 6
    if varMonth <> 7 OR varMonth <> 8 OR varMonth <> 9 OR varMonth <> 10 OR
    varMontn <> 11 OR varMontn <> 12 then varMonth = varMonth + 6
    varYear = Year(date)
    varNewEndDate = varYear & _
    "-" & Right(Cstr(varMonth + 100),2) & _
    "-" & Right(Cstr(varDay + 100),2)
    end if
    b]else
    ' this is the problem
    varNewEndDate = dateAdd("m", varPeriod, varAdvertEndDate)
    end if

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

    However this dateadd function turns the date into a local format rather than
    the ISO YYYY-MM-DD which i require it to be.

    Has anoyone got any ideas how to tackle this??

    many thanks

    loz howlett

    newedgemedia.co.uk Guest

  2. Similar Questions and Discussions

    1. Date Format Problem - SQL Server Insert From Web Application
      Hi, I've written a short aspx file so that end users can insert lines into our SQL server database. The following string is sent by Internet...
    2. converting date into database date format(newbie)
      Hi! U can convert "8-Aug-03" into mysql date which requires yyyy-mm-dd format as below. <?php date("Y-m-d",strtotime("8-Aug-03")); ?>
    3. Date functions in ASP
      ISDATE(...) or if you want to find the last day of the current month, set the date to the first, add one month using dateadd, minus 1 day. ...
    4. ASP & Date Functions
      Hi, I was wondering if there was a function in ASP that checks a date to see if it is valid or not. I am aware of the IsDate function, but I...
    5. Date Format for other locale settings SQL Server
      Hello, I have problems with Storing Dates into SQL Server. I am using ASP 3.0 to do so. When I change my locale settings to "Chinese - Taiwan"....
  3. #2

    Default Re: VB Date functions into ISO format for SQL server

    SQL Server is perfectly capable of handling the date manipulation on its
    own. That way, you don't have to worry about formatting since there's only
    one server involved and no dates are passed around as strings.
    Sample procedure to add any number of months to an ad:

    CREATE PROCEDURE [ExtendAd] (
    @AdID INT,
    @NumMonths INT
    )
    AS
    DECLARE @CurrentDate SMALLDATETIME
    DECLARE @EndDate SMALLDATETIME
    SELECT @EndDate = AdvertEndDate FROM AdTable WHERE AdID=@AdID

    SET @CurrentDate = CAST(LEFT(CONVERT(VARCHAR,GETDATE(),120),10) AS
    SMALLDATETIME) --all this cast/convert business just chops the time off of
    the current date/time stamp
    IF @EndDate < @CurrentDate
    SET @EndDate = @CurrentDate

    UPDATE AdTable
    SET AdvertEndDate = DATEADD(m,@NumMonths,@EndDate)
    WHERE AdID=@AdID
    GO

    "newedgemedia.co.uk" <webforumsuser@macromedia.com> wrote in message
    news:cvsmu5$dgs$1@forums.macromedia.com...
    > Hi everyone,
    >
    > I am developing a advertising portal site for villa rentals. In which we
    > require to charge for advertising on a 6 or 12 month basis. Each advert
    has an
    > advert end date, which is stored in an SQL database as a shortdatetime,
    with a
    > short date format.
    >
    > Someone can add 6 months or 12 to their advert even when the advert end
    date
    > has passed. This part of the coding is fine, no problem. It is however
    when
    > someone pays for the advert in advance which cause a problem. As the
    advert end
    > date needs to be updated by 6 or 12 months from the advert end date in the
    > database.
    >
    > Now I have all sort of problems with the date function, and therefore
    have
    > converted everything into ISO format. When i need to do is read the date
    into
    > the script, convert it to ISO, add the period to it (i.e. 6 or 12 months)
    then
    > put it into a form hidden field. this is the code thus far....
    >
    > ------------------------
    > 'get new end date
    > varAdvertEndDate = (rsProp.Fields.Item("AdvertEndDate").Value)
    > varPeriod = request.querystring("period")
    > if varAdvertEndDate < Date() then
    > if varPeriod = 12 then
    > varDay = Day(date)
    > varMonth = Month(date)
    > varYear = Year(date) + 1
    > varNewEndDate = varYear & _
    > "-" & Right(Cstr(varMonth + 100),2) & _
    > "-" & Right(Cstr(varDay + 100),2)
    > end if
    > if varPeriod = 6 then
    > varDay = Day(date)
    > varMonth = Month(date)
    > if varMonth = 7 then varMonth = 1
    > if varMonth = 8 then varMonth = 2
    > if varMonth = 9 then varMonth = 3
    > If varMonth = 10 then varMonth = 4
    > if varMonth = 11 then varMonth = 5
    > if varMonth = 12 then varMonth = 6
    > if varMonth <> 7 OR varMonth <> 8 OR varMonth <> 9 OR varMonth <> 10 OR
    > varMontn <> 11 OR varMontn <> 12 then varMonth = varMonth + 6
    > varYear = Year(date)
    > varNewEndDate = varYear & _
    > "-" & Right(Cstr(varMonth + 100),2) & _
    > "-" & Right(Cstr(varDay + 100),2)
    > end if
    > b]else
    > ' this is the problem
    > varNewEndDate = dateAdd("m", varPeriod, varAdvertEndDate)
    > end if
    >
    > -------------------------------------
    >
    > However this dateadd function turns the date into a local format rather
    than
    > the ISO YYYY-MM-DD which i require it to be.
    >
    > Has anoyone got any ideas how to tackle this??
    >
    > many thanks
    >
    > loz howlett
    >

    CMBergin 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