Solved

Get Previous Month in VB6

Posted on 2006-06-13
3
462 Views
Last Modified: 2008-02-01
Experts,

I am writing a VB6 program and I would like to have it use previous month- instead of the current month.  The current syntax is:

txtDay.Value=Format(Now(), "dd")
txtMonth.Value=Format(Now(), "mm")
txtYEar.Value=Format(Now(), "yy")


I need to change the now() part to reflect the previous month.  Please advise.  I need to use the existing code.  Thanks!
0
Comment
Question by:jjrr007
  • 2
3 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 250 total points
ID: 16894738
txtDay.Value=Format(Now(), "dd")
txtMonth.Value=Format(dateadd("m", -1,Now()), "mm")
txtYEar.Value=Format(dateadd("m", -1,Now()), "yy")
0
 
LVL 143

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 250 total points
ID: 16894746
>I need to change the now() part to reflect the previous month.  Please advise.  I need to use the existing code.  Thanks!

you would need to create a function called NOW() yourself returning the value of dateadd("m",-1,date())
0
 
LVL 9

Expert Comment

by:dancebert
ID: 16895063
What do you mean by 'previous month'?  angelIII gave you a solution for the same day of the month in the previous month.  For example if today is 6/13/06, his dateadd call will return 5/13/06.  But what if today 10/31/06?  There is no 9/31/06, the dateadd call will return 9/30/06.  Is that what you want?
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

830 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