Skip to main content
Inspiring
June 24, 2008
Question

Timestamp plus 7 days

  • June 24, 2008
  • 3 replies
  • 591 views
ASP VBScript and MySQL.

I need to add this:
Now() + INTERVAL 7 DAY

to this:
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param12", 135, 1, -1, MM_IIF(Request.Form("fld_enddate"), Request.Form("fld_enddate"), null)) ' adDBTimeStamp

But what ever I am doing isn't working. The old way that DW constructed the insert form worked a treat, but this way doesn't allow me to do this now.

This is how it was in the old insert statement:
MM_columnsStr = "blahblah...|fld_enddate|',Now() + INTERVAL 7 DAY,|...blahblah"

Any ideas?

Thanks

Mat
This topic has been closed for replies.

3 replies

Inspiring
June 25, 2008

"matthew stuart" <webforumsuser@macromedia.com> wrote in message
news:g3qvri$oh7$1@forums.macromedia.com...
> ASP VBScript and MySQL.
>
> I need to add this:
> Now() + INTERVAL 7 DAY
>
> to this:
> MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param12",
> 135, 1,
> -1, MM_IIF(Request.Form("fld_enddate"), Request.Form("fld_enddate"),
> null)) '
> adDBTimeStamp
>
> But what ever I am doing isn't working. The old way that DW constructed
> the
> insert form worked a treat, but this way doesn't allow me to do this now.
>
> This is how it was in the old insert statement:
> MM_columnsStr = "blahblah...|fld_enddate|',Now() + INTERVAL 7
> DAY,|...blahblah"

I do something similar for some forms I make for in-house users when
updating some content for display on our website. I am also using classic
ASP and mySQL.

Because of the differences in the way the Windows server "interprets" time
and the way mySQL wants time formatted, I had to do some things... don't
know if any of these will help or not.

In my recordset, I did the following:
SELECT *, DATE_FORMAT(EndDate, '%Y-%m-%d') AS EndDate, DATE_FORMAT(editDate,
GET_FORMAT(DATETIME, 'USA')) AS editDate

This forced the output of the date (in a field that could be updated) to NOT
conform to the Windows standard of M-D-YY and to display as YYYY-MM-DD so
that the end-user didn't have to change the date, and the datetime just
ouputs the date and time in US standards.

When I wanted the system to format date and time stuff for fields that could
record when the record was last edited and/or to use a "today" value for
dates, in the area after all my recordset info in the page I created two
functions: a "myDate" and a "myNow" to conform to mySQL formats...

<%
Function myDate()
myDate = Year(Now) & "-" & Right("0" & Month(Now), 2) & "-" & Right("0"
& Day(Now), 2)
End Function
%>

<%
Function myNow()
myNow = Year(Now) & "-" & Right("0" & Month(Now), 2) & "-" & Right("0" &
Day(Now), 2) & " " & Right("0" & Hour(Now), 2) & ":" & Right("0" &
Minute(Now), 2) & ":" & Right("0" & Second(Now), 2)
End Function
%>

So instead of using <%= Date() %>, I would now use <%= myDate() %>. Instead
of <%= Now() %> to get a timestamp, I would use <%= myNow() %>


To modify these for a week from "today" is just a matter of adding a +7 to
the mix:

full timestamp
<%
Function nextWeek()
nextWeek = Year(Now) & "-" & Right("0" & Month(Now), 2) & "-" &
Right("0" & Day(Now)+7, 2) & " " & Right("0" & Hour(Now), 2) & ":" &
Right("0" & Minute(Now), 2) & ":" & Right("0" & Second(Now), 2)
End Function
%>

just the date
<%
Function nextWeek2()
nextWeek2 = Year(Now) & "-" & Right("0" & Month(Now), 2) & "-" &
Right("0" & Day(Now)+7, 2)
End Function
%>






Inspiring
June 24, 2008
> I need to add this:
> Now() + INTERVAL 7 DAY
>
> to this:
> MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param12",
> 135, 1,
> -1, MM_IIF(Request.Form("fld_enddate"), Request.Form("fld_enddate"),
> null)) '
> adDBTimeStamp
>
> But what ever I am doing isn't working. The old way that DW constructed
> the
> insert form worked a treat, but this way doesn't allow me to do this now.
>
> This is how it was in the old insert statement:
> MM_columnsStr = "blahblah...|fld_enddate|',Now() + INTERVAL 7
> DAY,|...blahblah"



In the Command window, declare another variable and define it as:
Date() + 7


Inspiring
June 25, 2008
Check out the ASP dateadd function it will add any part of a date day, week, month, year, hour -
like this:
dateAdd("ww", 1, date())
Adds one week to your date;

Check out this page of ASP Functions:
http://www.w3schools.com/VBscript/vbscript_ref_functions.asp

IF you want to be able to check if a date in your db to see if its less than a week old you could use the same in your query:
"SELECT * FROM TABLE WHERE dateCheck >= '"&dateAdd("ww", -1, date())&"'"
Of course using a paramter is better, but the code for the variable would be the same.
Inspiring
June 24, 2008

"matthew stuart" <webforumsuser@macromedia.com> wrote in message
news:g3qvri$oh7$1@forums.macromedia.com...
> ASP VBScript and MySQL.
>
> I need to add this:
> Now() + INTERVAL 7 DAY
>
> to this:
> MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param12",
> 135, 1,
> -1, MM_IIF(Request.Form("fld_enddate"), Request.Form("fld_enddate"),
> null)) '
> adDBTimeStamp
>
> But what ever I am doing isn't working. The old way that DW constructed
> the
> insert form worked a treat, but this way doesn't allow me to do this now.
>
> This is how it was in the old insert statement:
> MM_columnsStr = "blahblah...|fld_enddate|',Now() + INTERVAL 7
> DAY,|...blahblah"
>
> Any ideas?

yeah, but not sure what you're doing there.... does it have to be that way
or are you open to an alternative? Are you just basically trying to put in a
date a week from today for something like an "end date" for when something
is online?