Solved

Date Issues

Posted on 2001-06-11
8
135 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
 
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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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.
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…

706 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now