Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding Months to a date

Status
Not open for further replies.

pechettysuguna

Programmer
Oct 11, 2001
39
JP
Hi!
I am doing the project in VB and SQL as a Backend. This is my first project in VB.
Problems:--
1) Helding dates.
a) How to give a text fields date validation in "DD/MM/YYYY" format (like Foxpro on key press)?
b) As well as in SQL, how to set the date datatype in "DD/MM/YYYY" format ?
c) How to give the default date in SQL. Since if the date field is kept blank, it gives an error in INSERT Statement.

2) How to add months to a date?
I have a start date. To this day I am adding 183 days, 365 days, 549 days, 730 days, 913 days, 1095 days to get six different date after a interval of 6 month. But due to leap year it is not giving me the exact date which I required.
I got this ** = DateAdd("M", 12, Me.[PurchaseDate]) ** from U R site. I hope it works properly.

Regards,
Suguna.
 

1a) You can set a format on text box in Access so it will only acept a date format.

1b) Format(datecol,"dd/mm/yyyy")

1c) Set the default date in the table to Date() if you only want a date or Now() if you want current date and time. Open the table in design mode and look at the lower part of the screen for the Default row.

2) Dateadd("m", 6, PurchaseDate) adds 6 months to the PurchaseDate. You can add 12, 18, 24, etc. for the six month intervals.
Terry L. Broadbent
FAQ183-874 contains tips for posting questions in these forums.
NOTE: Reference to the FAQ is not directed at any individual.
 
1a) I am using VB5 as my frontent tool and not Access.

1b) While calling form the database this code works.
***** Format(datecol,"dd/mm/yyyy") ******
But while inserting how to insert, since the user will be entering in "DD/MM/YYYY" format. It is giving error.

1c) I didn't got U? In SQL, there is a column DEFAULT VALUE, where I have to wrote (01/01/1900), So even if the field in kept empty, It is not giving error.

Brief idea how my form works:---
While entering the details, the user don't know the date, so he keeps it empty. After few days he search for that record. So while retreving, it gives 01/01/1900 date in the text field. I want it empty.
How to do this.

2)Thanks, This function is working excellently.
= DateAdd("M", num, startdt)

3) On gotfocus, I want the text field to be selected.I have more than 20 to 25 text fields in a form. How to write a procedure for this.

Thanks, For Quick Reply.
Regards,
Suguna
 

May I suggest that you post your questions in a VB forum (forum222). This is not a VB forum nor a SQL server forum. My answers were based on the fact that you posted your question to a Microsoft Access forum. Terry L. Broadbent
FAQ183-874 contains tips for posting questions in these forums.
NOTE: Reference to the FAQ is not directed at any individual.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top