Excel String to date object? - go back a custom number of days? :) from Mr Excel
 Search   Memberlist   Usergroups   Favorites   Statistics   Register

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

apwdweb
Board Regular

Joined: 24 Aug 2002
Posts: 56

Status: Online

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

Wed Jan 14, 2004 6:08 am

SIXTH SENSE
Board Master

Joined: 29 Oct 2003
Posts: 955

Flag:

Status: Offline

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.

_________________
There is always a better way!!

Wed Jan 14, 2004 6:26 am

Chitosunday
Board Master

Joined: 14 Jul 2003
Posts: 443

Flag:

Status: Offline

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
_________________
Mr Young at Heart - Learning is like chasing the wind, it's boundless.

Wed Jan 14, 2004 6:35 am

white6174
Board Master

Joined: 07 May 2002
Posts: 133
Location: CALIFORNIA

Status: Offline

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

Wed Jan 14, 2004 6:39 am

apwdweb
Board Regular

Joined: 24 Aug 2002
Posts: 56

Status: Online

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

Wed Jan 14, 2004 1:20 pm

Chitosunday
Board Master

Joined: 14 Jul 2003
Posts: 443

Flag:

Status: Offline

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)
_________________
Mr Young at Heart - Learning is like chasing the wind, it's boundless.

Wed Jan 14, 2004 2:15 pm

apwdweb
Board Regular

Joined: 24 Aug 2002
Posts: 56

Status: Online

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.

Sun Jan 18, 2004 5:03 am

Chitosunday
Board Master

Joined: 14 Jul 2003
Posts: 443

Flag:

Status: Offline

'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)
_________________
Mr Young at Heart - Learning is like chasing the wind, it's boundless.

Mon Jan 19, 2004 3:14 am

Chitosunday
Board Master

Joined: 14 Jul 2003
Posts: 443

Flag:

Status: Offline

or use this

a = 15
b = 1
c = 2004
ActiveCell = Format(Application.ExecuteExcel4Macro("workday(""" & DateSerial(c, b, a) & """,-90)"), "mm-dd-yy")
_________________
Mr Young at Heart - Learning is like chasing the wind, it's boundless.

Mon Jan 19, 2004 3:31 am
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

Forum Jump:
 Jump to: Select a forum MrExcel Forums----------------Excel QuestionsInternational forumMicrosoft AccessTechnical issues and Future development Holy Macro! Books----------------Holy Macro! Products The Lounge----------------Max Cells Lounge Announcements----------------About This BoardHall of Fame WinnersTest Here

Page 1 of 1

Forum Rules:
 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot vote in polls in this forum