# String to date object? - go back a custom number of days? :)

This is a discussion on String to date object? - go back a custom number of days? :) within the Excel Questions forums, part of the Question Forums category; Hi All, I'm stumped and wonder if anyone can help me figure this one out I have a custom date ...

1. ## String to date object? - go back a custom number of days? :)

Hi All,

I'm stumped and wonder if anyone can help me figure this one out

I have a custom date stored via three integer variables a,b,c

a = 10 '10 Dec
b = 12 '12th
c = 2003 '2003 year

Suppose i need to convert this date to a date that is exactly 30 days back or 90 days or better yet a Custom number of days back.

I was wondering if there is a good way to do this accurately to reflect leap years and the number of days for each month.

Jennifer

2. hi!
is this what you mean?

******** ******************** ************************************************************************>
 Microsoft Excel - Book1 ___Running: xl2000 : OS = Windows XP
 (F)ile (E)dit (V)iew (I)nsert (O)ptions (T)ools (D)ata (W)indow (H)elp (A)bout
 F1D2F2 =

A
B
C
D
E
F
1
daymonthyeardatedays*backthe*date*90*days*back*before*12-*10-*2003
2
10122003December*10,*200390September*11,*2003
 Sheet2 *

[HtmlMaker 2.42] To see the formula in the cells just click on the cells hyperlink or click the Name box
PLEASE DO NOT QUOTE THIS TABLE IMAGE ON SAME PAGE! OTHEWISE, ERROR OF JavaScript OCCUR.

3. Using VBA or macro for date less 30 days

a = 10
b = 12
c = 2003
MsgBox DateSerial(c, b, a) - 30

using formula
=date(c,b,a)-30

4. ## Re: String to date object? - go back a custom number of days

heres something to try
just an example I made up

hope it helps
steve w

Private Sub CommandButton1_Click()
Dim a As Variant
Dim b As Variant
Dim c As Variant

a = 10 '10 Dec
b = 12 '12th
c = 2003 '2003 year

TextBox1.Value = DateSerial(c, b, a)

TextBox2.Value = DateSerial(c, b, a) - TextBox3.Value 'textbox3 has value you want to subtract

End Sub

5. ## Re: String to date object? - go back a custom number of days

Great! thank you!

now what if i want to convert the date back to a string after i subtract (go back) 90 days?

Thanks

6. a = 10
b = 12
c = 2003
ActiveCell = "'" & DateSerial(c, b, a) - 90
a = Day(DateSerial(c, b, a) - 90)
b = Month(DateSerial(c, b, a) - 90)
c = Year(DateSerial(c, b, a) - 90)

7. ## Re: String to date object? - go back a custom number of days

chitosunday

Thanks for your help. DO you know if it is possible to count 90 days backwards excluding weekends?

Thanks.

8. 'use the workday function
a = 15
b = 1
c = 2004
ActiveCell.Formula = "=workday(" & """" & DateSerial(c, b, a) & """" & ",-90)"
ActiveCell.Value = "'" & ActiveCell.Value
a = Day(ActiveCell)
b = Month(ActiveCell)
c = Year(ActiveCell)

9. or use this

a = 15
b = 1
c = 2004
ActiveCell = Format(Application.ExecuteExcel4Macro("workday(""" & DateSerial(c, b, a) & """,-90)"), "mm-dd-yy")

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•