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

Dim as date, with a few other questions?

Status
Not open for further replies.

smiler44

Technical User
Sep 18, 2009
83
GB
I am scraping some text from the screen that is in the format of 02/02/2012 and putting it into a variable
I am trying to delcare my variable as a date using dim dayyt as date. Attachmate does not seem to like this.
please can you tell me what I should be using?
I want to add 3 days to the date, how do I do that?
If by adding 3 days the date is a Saturday or a Sunday I want to add 2 or 1 days as requred.
How to I work out if a date is a sataurday or Sunday

thank you in advance
smiler44
 
i have something like this
Code:
    mydate = sess.getstring (2,63,8)
    
    mm = mid(mydate,1,2)
    dd = mid(mydate,4,2)
    yy = mid(mydate,7,2)
    
    
    tday = DateSerial(yy,mm,dd)
    daynumber = weekday(tday)

    select case daynumber
        case 1  : 'dosomething this is sunday
        case 2  : 'dosomething
        case 3  : 'dosomething
        case 4  : 'dosomething
        case 5  : 'dosomething
        case 6  : 'dosomething
        case 7  : 'dosomething this is saturday
    end select
    
    newdate = tday + 5
    
    msgbox newdate
 
remy988,
My apologies for not replying, no excuse and unprofessional of me. I am sorry.
think i can follow it, but if i have understood yy = mid(mydate,7,2) should be yy = mid(mydate,9,2) for my use.
I have never understood select case but I think I can skip that and go to newdate = tday + 5 . i will have a practice
thank you
smiler44
 
Code:
daynumber = weekday(tday)

weekday returns a numeric value that corresponds to a day,
so 1 = sunday, 2= monday, 3 = tuesday...etc

so if tday is tuesday, the numeric value is 3.

assuming today is tuesday, if you use newdate = tday + 5, then you would get sunday as your date. if you don't want sunday, then you would need to use select case
Code:
    select case daynumber
        case 1  : 'dosomething this is sunday
        case 2  : 'dosomething
        case 3  : newdate = tday + 6 '6 would give you monday
        case 4  : 'dosomething
        case 5  : 'dosomething
        case 6  : 'dosomething
        case 7  : 'dosomething this is saturday
    end select
 
remmy998,
I'll give selcet case ago thank you for explaining it. I tried the rest of the code last night and will try it again in case i made a mistake. I may have used 28/02/12 instead of 28/02/13 but adding 5 days gave me the wrong date in march, starting with a date in january gave me the right date in February.

appreciate the help
smiler44
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top