ASP date from db - 2 months

Posted on 2012-08-29
Medium Priority
Last Modified: 2012-08-29
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).
Question by:fksolutions
LVL 143

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 400 total points
ID: 38345139
2 month back :
dateadd("m", -2, your_date_value)

month / name is

Author Comment

ID: 38345166
 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)
LVL 54

Accepted Solution

Scott Fell,  EE MVE earned 1600 total points
ID: 38345202
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
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
LVL 54

Expert Comment

by:Scott Fell, EE MVE
ID: 38345219
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.
LVL 11

Expert Comment

ID: 38345653
You missed that DateAdd returns a value, so use it like this

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

Open in new window


Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are two main kinds of selectors in CSS: One is base selector like h1, h2, body, table or any existing HTML tags.  For instance, the following rule sets all paragraphs (<p> elements) to red: (CODE) CSS also allows us to define our own custom …
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question