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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can I use Dateadd in Extra only?

Status
Not open for further replies.

jamesbt

Technical User
May 30, 2011
24
GB
Hi all,

I need to get todays date, and then generate a new date 7 days from todays date.

I can do this in excel and it works

Dim newdate

newdate = DateAdd("d", 7, Date)' adds however many days

newdate = Format(newdate, "ddmmyy") 'formats my date

MsgBox newdate

In this case I will only be working with Extra, I will not be running excel.

When I use the above code in Extra I get a Variable Dateadd undefined

Is there a method in which this issue can be resolved?

Many thanks,

James
 



hi,

A DATE is a NUMBER, not text. the Format function returns TEXT!!!

Simply do this...
Code:
Dim newdate as date, txtdate as string

newdate = Date + 7                    'to use in calculations & sorting

txtdate = Format(newdate, "ddmmyy")   'to use on screen

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
would this work for you?

Code:
    tday = date
    
    newdate = tday + 7
    
    newdate = format(newdate,"ddmmyy")
    
    msgbox newdate
 


What value does tday have?

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 

I meant to say, why even use tday? What value does that add to the issue?

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Yes the above worked perfectly, I know some of this is quite basic but im starting to understand... I've been reading alot and spent a good few hours at home working at this on excel yesterday.

This morning I thought id try it, only to find it didnt work work.

Now it does.

Skip, many thanks once again for your support.
 
In anwer you your above question,

What value does tday have?

tday = date ' with out this date
newdate = tday + 7 ' we would not have a date to add 7 to
newdate = format(newdate,"ddmmyy"

Without tday, it would not work.

I think?
 
vzachin, thanks for your help as well!
much appreciated.

Kind regards,

James
 




This works perfectly well, although I do not recommend using the SAME varialbe as a DATE and a STING...
Code:
 newdate = Date + 7 
 newdate = format(newdate,"ddmmyy")

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
I did try the above and it did not work. As I said my post, I thought thats why it did what it did.
 



work in my Extra VB Editor.

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
james,

here's another variation. i found this in the help files.

Code:
Dim nextweek
 
nextweek=CVar(Date)+7
 
nextweek = format(nextweek,"ddmmyy")
        
msgbox nextweek

zach
 
Thanks Zach, there is just so much information to get through on this site.
Ive just posted an update on my Exel to Extra Loop problem,

I used alot of the code you supplied on another thread.

Ive got my loop working, now i need to take it a step further and if I encounter an error on a certain scren, I need to do something then go to the next line in excel.

If I dont get the error, I just need to continue.

I'm really struggling with this.

Thanks,

James
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top