Solved

Date Issues

Posted on 2001-06-11
8
139 Views
Last Modified: 2012-03-15
Hello!

My name is Assaf Lasry and I am a junior programmer. I have a small problem with dates. I am building an application that registers members, and the membership expires on August 31 of every year (31/08/xxxx), REGARDLESS when did the person registered. Example, if I registered on november 23 2001 (23/11/2001), my registration expires on August 31 2002 (31/08/2002). Another example, if I registered on August 30 2001 (30/08/2001), my registration will expire on august 31 2001 (31/08/2001). I want to create a form where I have 2 text boxes. One text boxe will show the current date, and the other will show August 31 of the PREVIOUS year. Example, if today we are June 11 2001 (11/06/2001), the other text box has to show August 31 2000 (31/08/2000).

What can I do in order to achieve that? Please I need help.

Thank you in advance,
Assaf Lasry.
0
Comment
Question by:AssafL
8 Comments
 
LVL 1

Accepted Solution

by:
ShaneCourtrille earned 100 total points
ID: 6178885
Are you using a DateTime Picker control?  This would probably be preferable to the textbox and it comes with Visual Basic (at least in 6 it does).

If you're just using a textbox..

Dim myDate As Date
Dim myDate2 As Date

myDate = Format(Text1.Text, "mm/dd/yyyy") ' Get the original date

myDate = myDate - 356 ' Minus a year

myDate2 = "31/08/" + Format(myDate, "yyyy") ' Get the new date

Text2.Text = myDate2 ' Write it out

0
 
LVL 1

Expert Comment

by:ShaneCourtrille
ID: 6178891
PS If you wanted to switch to a DateTime picker control all you'd need to do is use switch anywhere you see
Text1.Text to DTPicker1.Value same thing with Text2.Text to DTPicker2.Value.
0
 
LVL 4

Expert Comment

by:beckingh
ID: 6178895

txtToday.text = format(now(), "DD/MM/YYYY")
txtLastYear.text = "31/08/" & cstr(year(now()) - 1)

0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

 
LVL 38

Expert Comment

by:PaulHews
ID: 6178896
Private Sub Command1_Click()
    Text1 = Format(Date, "short date")
    If Date < DateSerial(Year(Date), 8, 31) Then
        Text2 = Format(DateSerial(Year(Date) - 1, 8, 31), "short date")
    Else
        Text2 = Format(DateSerial(Year(Date), 8, 31), "short date")
    End If
End Sub
0
 
LVL 38

Expert Comment

by:PaulHews
ID: 6178949
>One text boxe will show the current date, and the other will show August 31 of the PREVIOUS year.

My example will show the past expiration date.  Not sure if that is what you needed.  Otherwise you could just use:


Text2 = Format(DateSerial(Year(Date) - 1, 8, 31), "short date")

to show the Aug 31 date of the previous calendar year.
0
 
LVL 3

Expert Comment

by:Hornet241
ID: 6179380
Try this, you can format the date results how you want.

Text1.Text = Date

Text2.text = DateAdd("yyyy", -1, Date)
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7135901
Hi AssafL,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will suggest to:

    Accept ShaneCourtrille@idg's comment(s) as an answer.
*** The FIRST correct answer to this simple Q

AssafL, if you think your question was not answered at all or if you need help, you can simply post a new comment here.  Community Support moderators will follow up.

EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer
0
 
LVL 1

Expert Comment

by:Computer101
ID: 7168341
Comment from expert accepted as answer

Computer101
E-E Moderator
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Suggested Solutions

Title # Comments Views Activity
Excel VBA combine two working workbooks 8 60
Visual Basic Excel Formatting error 4 127
passing parameter in sql procedure 9 65
backup program with robocopy 6 45
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

856 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