|
-
May 1st, 2008, 04:50 PM
#1
Thread Starter
Lively Member
HELP: Solution for Posted Date the 15th of the month OR 1st of the following month
Hi guys
could you help what would be the best way to implement this logic
Example
If ToDate is May 14 2008 then posted date is 20080515
and if ToDate is May 31 2008 then posted date is 20080601
Basicly I would like to create a logic that would work like this
ToDate = 20000114 THEN PostedDate = 20000115 <-- The 15th of the same month
ToDate = 20000131 THEN PostedDate = 20000201 <-- The First of the following month
ToDate = 20001231 THEN PostedDate = 20010101 <-- The year Change (The first of the following month and year)
Thank you
Last edited by ndondo; May 1st, 2008 at 04:59 PM.
-
May 1st, 2008, 05:00 PM
#2
Thread Starter
Lively Member
Re: HELP: Solution for Posted Date the 15th of the month OR 1st of the following month
and to add more info
ToDate can be either the 14th of the month or the last day of the month (Can be 28, 30, or 31)
-
May 1st, 2008, 06:49 PM
#3
Re: HELP: Solution for Posted Date the 15th of the month OR 1st of the following month
Simple:
PostedDate = ToDate + 1
or someone may want to use more "academic" function:
PostedDate = DateAdd("d", 1, ToDate)
That will work for any ToDate. PostedDate is always the next day.
Now, if ToDate is in the form like 20000114 then you need to convert it to Date data type then do adding or use DateSerial function:
ToDate = 20000114
PostedDate = CLng(Format(DateSerial(ToDate\10000, (ToDate\100) Mod 100, (ToDate Mod 100) + 1), "yyyymmdd"))
Last edited by anhn; May 1st, 2008 at 06:56 PM.
-
May 5th, 2008, 11:53 AM
#4
Thread Starter
Lively Member
Re: HELP: Solution for Posted Date the 15th of the month OR 1st of the following month
hmm thats simple enough
thanks..
-
May 5th, 2008, 12:21 PM
#5
Re: HELP: Solution for Posted Date the 15th of the month OR 1st of the following month
Does this resolve your issue or do you still have questions?
-
May 5th, 2008, 01:23 PM
#6
Re: HELP: Solution for Posted Date the 15th of the month OR 1st of the following month
With all due respect, I do not believe anhn's answer covers the stated problem. Assuming your dates are always in the format "yyyymmdd", code like the following should be used:
Code:
Dim ToDate As String
Dim PostedDate As String
Dim dtmToDate As Date
Dim dtmPostedDate As Date
' get ToDate into a Date variable:
dtmToDate = DateSerial(Left$(ToDate, 4), Mid$(ToDate, 5, 2), Right$(ToDate, 2))
If Day(dtmToDate) >= 15 Then
' post first of next month
dtmPostedDate = DateSerial(CInt(Year(DateAdd("m", 1, dtmToDate))), _
CInt(Month(DateAdd("m", 1, dtmToDate))), 1)
Else
' post 15th of current month
dtmPostedDate = DateSerial(Year(dtmToDate), Month(dtmToDate), 15)
End If
PostedDate = Format$(dtmPostedDate, "yyyymmdd")
The above code will also handle the year change.
"It's cold gin time again ..."
Check out my website here.
-
May 5th, 2008, 04:20 PM
#7
Re: HELP: Solution for Posted Date the 15th of the month OR 1st of the following mont
 Originally Posted by BruceG
With all due respect, I do not believe anhn's answer covers the stated problem.
I don't want to argue. Let the OP test the way I presented.
Advance 1 day is the simplest process regardless of day, month or year: just add 1 to the given day.
What the OP want is to have the next day after the 14th day of a month and the next day after the last day of a month.
Have you ever tried:
Code:
? DateSerial(2008, 2, 31) '-- 02 Mar 2008
? DateSerial(2008, 4, 31) '-- 01 May 2008
? DateSerial(2007, 12, 35) '-- 04 Jan 2008
? DateSerial(2008, 3, 0) '-- the last day of Feb-2008 (don't care 2008 is a leap year or not)
Last edited by anhn; May 5th, 2008 at 05:28 PM.
-
May 5th, 2008, 06:48 PM
#8
Re: HELP: Solution for Posted Date the 15th of the month OR 1st of the following month
I stand corrected. Your way works if the ToDate is one of the two possibilities he mentioned (the 14th or the last day of the month). With my answer I was considering if days other than those exact two would be input.
"It's cold gin time again ..."
Check out my website here.
-
May 5th, 2008, 07:48 PM
#9
Re: HELP: Solution for Posted Date the 15th of the month OR 1st of the following month
 Originally Posted by BruceG
I stand corrected. Your way works if the ToDate is one of the two possibilities he mentioned (the 14th or the last day of the month). With my answer I was considering if days other than those exact two would be input.
 Originally Posted by BruceG
With all due respect, I do not believe anhn's answer covers the stated problem. .
The code I provided was enough for him to solve his problem as requested and that is "simple enough" (as he commented) with just a single line.
He didn't ask for a general case of any date and I didn't intend to solve that.
-
May 5th, 2008, 11:38 PM
#10
Re: HELP: Solution for Posted Date the 15th of the month OR 1st of the following month
In the end, thread starter will have to check output based on sample data himself... but if this is accounting system related then I would have to agree with BruceG, no sense in posting just transactions before post date and excluding all others.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|