ASP date from db - 2 months

I am a beginner at ASP, I need help with a date function.
I am working with an old ASP VB script.

I have a date in DB.

<%=rs("start")%> (my date in db for example: 2012-09-01)

Fisr question:
How do I write a date 2 months back? - 2012-07-01

And second question:
How do I write same as question one but instead of full date just show 07 or Juli(month name).
fksolutionsAsked:
Who is Participating?
 
Scott Fell, EE MVEConnect With a Mentor Developer & EE ModeratorCommented:
Fisr question:
How do I write a date 2 months back? - 2012-07-01
<%
theDate = rs("start") 'or whatever date you want
NewDate = dateadd("m",-2,theDate) '2 months back
response.write NewDate
%>

full date just show 07 or Juli(month name).
<%
theDate = rs("start") 'or whatever date you want
MonthNumber=month(theDate)
response.write MonthNumber ' should be 1,2,3....11, or 12
response.write monthname(MonthNumber) ' will be full month name like January.
response.write monthname(MonthNumber,True) 'will give you abbreviated month like Jan
%>
0
 
Guy Hengel [angelIII / a3]Connect With a Mentor Billing EngineerCommented:
2 month back :
dateadd("m", -2, your_date_value)
http://www.w3schools.com/vbscript/func_dateadd.asp

month / name is
month(your_date_value)
monthname(month(your_date_value))
http://www.w3schools.com/vbscript/func_month.asp
http://www.w3schools.com/vbscript/func_monthname.asp
0
 
fksolutionsAuthor Commented:
 <% 
 startdaterorligt = rs2("start")
 dateadd("m", -2, startdaterorligt) %>

Open in new window


gets error
Microsoft VBScript compilation error '800a0414'

Cannot use parentheses when calling a Sub

/include/johan201208.asp, line 538

dateadd("m", -2, startdaterorligt)
0
 
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
Is your recordset really called, rs2("start") otherwise it will be counted as a function.  You can use rs2.Fields.Item("start").Value to be sure.  

You need to make sure your recordset is created in your include file or before the code where you insert the include file on the main page.
0
 
G_HCommented:
You missed that DateAdd returns a value, so use it like this

<% 
 startdaterorligt = rs2("start")
SomeThing = DateAdd("m", -2, startdaterorligt)
%>

Open in new window

GH
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.