C++/VB - DateDiff function

Asked By macgolfers
08-Feb-10 12:36 PM
I use a formula that calculates using the number of weeks in the year
to date. I have used the DateDiff function, but with the way I use it,
I have to manually update the current calendar year (see below).

(DateDiff ("w",#01/01/2010# , CurrentDate)

Is there another way to calculate the # of weeks that have elapsed in
the current year that will work without updating?
I am using this formula in Crystal Reports 8.5 and 10.
CurrentDate
(1)
DateDiff
(1)
Weeks
(1)
Year
(1)
Day
(1)
  macgolfers replied to macgolfers
08-Feb-10 02:57 PM
After some more research, I found that I can create a variable "Year"
with this formula:
Date( Year(currentdate), 1, 1)
And use that for the first date/day of the current year.
DateDiff ("w",{@Year}, CurrentDate)
Create New Account
help
s that? - - HTH, Bob Barrows ha. Good question. Wrong newsgroup. -ralph The VBS version is DateDiff() - - Crash ~ Yogi Berra ~ thanks for the responses. i worked it out with code. was simpler than i thought. If DateDiff("s", dtime, Now) > 10 * 60 Then DateDiff( / interval / , date1, date2 [, firstdayofweek[, firstweekofyear]]) The interval argument must be one of the following values Expression Corresponds to yyyy Years q Quarters m Months y Days of year d Days w Weekdays ww Weeks of year h Hours n Minutes s Seconds But watch out: If you want to calculate the compare the days, not the years, this would become wrong dependent from the given birthdate: DateDiff("yyyy", dtmBirthdate, Now) In my case it would become right, because I was born at the beginning of the year. - - ??R In microsoft.public.scripting.vbscript message <4caf703d$0$6771$9b4e6d93 @newsspool3.arcor-online.net
the number reps. Scott '## cvs_cmd_begin '## ID = 2001 '## Description = "Report: Historical: Designer: CS Agent Summary by Day adj: Export Data" '## Parameters.Add "Report: Historical: Designer: CS Agent Summary by Day adj: Export Data", "_Desc" '## Parameters.Add "Reports", "_Catalog" '## Parameters.Add "2", "_Action" '## Parameters.Add "1 _Quit" '## Parameters.Add "Historical \ Designer \ CS Agent Summary by Day adj", "_Report" '## Parameters.Add "2", "_ACD" '## Parameters.Add "30", "_Top" '## Parameters.Add "60", "_Left" '## Parameters _Width" '## Parameters.Add "11010", "_Height" '## Parameters.Add "The report Historical \ Designer \ CS Agent Summary by Day adj was not found on ACD 2.", "_ReportNotFound" '## Parameters.Add "*", "_BeginProperties" '## Parameters.Add "72610", "Agent cvsSrv.Reports.ACD = 2 Set Info = cvsSrv.Reports.Reports("Historical \ Designer \ CS Agent Summary by Day adj") If Info Is Nothing Then If cvsSrv.Interactive Then MsgBox "The report Historical \ Designer \ CS Agent Summary by Day adj was not found on ACD 2.", vbCritical Or vbOKOnly, "Avaya CMS Supervisor" Else Set Log = CreateObject("ACSERR.cvsLog") Log.AutoLogWrite "The report Historical \ Designer \ CS Agent Summary by Day adj was not found on ACD 2." Set Log = Nothing End If Else b = cvsSrv all other | reps. | | | Scott | | | '## cvs_cmd_begin | '## ID = 2001 | '## Description = "Report: Historical: Designer: CS Agent Summary by | Day adj: Export Data" | '## Parameters.Add "Report: Historical: Designer: CS Agent Summary | by | Day adj: Export
Datediff function in Crystal Reports C++ / VB I am trying to create a formula in Crystal Reports 8.5 using the DateDiff function to calculate the number of weeks between a beginning date and today. However every time I put my information in, i tried to add and subtract parens everywhere I can think of to the following formula: DateDiff (ww, {relserv.bdate1} , CurrentDate) VB Crystal Discussions CurrentDate (1) Datediff (1) Relserv.bdate1 (1) Weeks (1) The interval is a string variable so needs to be in quotes: DateDiff ("ww
dDate = CDate(aLine(1) & " " & aLine(2) & " " & aLine(3)) outF.WriteLine sKey & Pad(Month(dDate)) & Pad(Day(dDate)) & Year(dDate) Loop And usually the input looks like this: AA1759L3 Jul 17 2015 4:00AM dDate = CDate(aLine(1) & " " & aLine(2) & " " & aLine(3)) outF.WriteLine sKey & Pad(Month(dDate)) & Pad(Day(dDate)) & Year(dDate) End If Loop There are usually several ways to solve a problem. Here is dDate = CDate(aLine(1) & " " & aLine(2) & " " & aLine(3)) outF.WriteLine sKey & Pad(Month(dDate)) & Pad(Day(dDate)) & Year(dDate) else 'OPTIONALLY INCLUDE "NOW" ENTRY outF.WriteLine sKey & Pad(Month(Now)) & Pad(Day(Now)) & Year(Now) end if Loop - - Crash ~ Napoleon Bonaparte ~ Awesome, thanks for your help! keywords: How, to
are the same (and the trace clearly shows they are when I print them, from year to second) the " = = " does not work. "> " works immediately after that in while-loop and the those odd problems. . . thanks. the code:. Trace(timeStart); / / printing / tracing time to output window COleDateTime year(timeStart.GetYear(), 1, 1, 0, 0, 0); while(timeStart > year) { year + = tsPerio; / / tsPerio = 15 min if(year = = timeStart) / / THIS ONE DOES NOT WORK when they are equal Trace(timeStart); } VC MFC Discussions resolve this? Dave Using the code I posted earlier, I replaced the " = = " with this: if( year > (timeStart-COleDateTimeSpan(0, 0, 0, 1)) && year < (timeStart+COleDateTimeSpan(0, 0, 0, 1)) ) Trace(timeCandleStart); / / year = = timeStart So checking if the tested time is between ]timeStart-one second, timeStart+one second