Solved

Date Issues

Posted on 2001-06-11
8
138 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

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…
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…
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…

770 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