Solved

Date Issues

Posted on 2001-06-11
8
142 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses
Course of the Month9 days, 3 hours left to enroll

615 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