Add one day to a date and save it as a new variable in Smalltalk - date

so here is the problem. I want to take a date from lastDate and put it to nextDate, but also add one day to the variable nextDate. Anyone know how to do that?
| lastDate nextDate |
lastDate := Date
newDay: 10
monthNumber: 5
year: 2019.
nextDate := lastDate.
HELP HERE
^nextDate

It would help to know which Smalltalk you are using.
I will use Smalltalk/X-jv branch for the examples as it is easies for me:
| lastDate nextDate |
lastDate := Date newDay: 10
month: 5
year: 2019.
nextDate := lastDate addDays: 1.
^ nextDate
To add one day you can use the #addDays: message to your lastDate.
Edit: due to comment
To add a year you can send message #addYears:

Related

Can I compare two dates in Smalltalk?

I have two dates which I need to compare, if one is past second. That means:
date1 := Date newDay: 10 month: 12 year: 2017
date2 := Date newDay: 1 month: 1 year: 2020
So in this case date2 is past date1, so I need this to be true.
But
date1 := Date newDay: 10 month: 12 year: 2017
date2 := Date newDay: 3 month: 7 year: 2015
should return false.
Anyone got hints? Appreciate!
I guess this depends on which dialect you are using, but ANSI standard already defines < for DateAndTime which seems similar to Date. I tried your code in Pharo and Dolphin and date1 < date2 works just fine for your needs (even if Date instantiation in Dolphin is a little bit different).

SSRS: Default Values for StartDate Parameter Based on EndDate Parameter

I'm working with SSRS and using Visual Studio 2012.
I have two parameters StartDate and EndDate and I configured default values for each.
The default values currently for both are the following:
StartDate: =DateAdd("d",-(Day(today)-1), Today)
EndDate: =Today() - 1
I want the values to bring in:
StartDate: 1/1/2017
EndDate: 1/31/2017
Basically, I want EndDate to be the previous day (e.g. EndDate for today would be 1/31/2017 since today is 2/1/2017.)
And then for StartDate, I want that to be the first day of the month that EndDate pulls in (e.g. since EndDate pulled in 1/31/2017, the StartDate should pull in 1/1/2017.)
However, with the current parameters in place, StartDate pulls in 2/1/2017 and EndDate pulls in 1/31/2017.
How do I get StartDate to pull in the 1st day of the month based on the value of EndDate?
For StartDate you can use:
=DateSerial(Today.AddDays(-1).Year,
Today.AddDays(-1).Month,
1)
Let me know if this helps.

Get Day, Month, and Year from Time in Go Language

I have an object like this:
type searchObj struct {
symbol string
dataType string
fromDate time.Time
toDate time.Time
}
I want to be able to parse out the day, month, and year from the fromDate and the toDate. How can I do this? Is there a better type to use like (Date) because I do not need the time piece of it?
so I want to be able to pass a date like this 02/19/2016 and be able to get data.Day = 19, date.Month = 02, date.Year = 2016.
I was trying something like this:
search.fromDate.Date.Month
search.fromDate.Date.Day
search.fromDate.Date.Year
This is an example of what I am currently using to create the searchObj:
time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC)
I am new to Go and thank you for the help!
All the methods you're looking for exist on the time.Time type. You can just do;
year := fromDate.Year()
month := fromDate.Month()
day := fromDate.Day()
EDIT:
I suppose it would be more concise to use time.Date like so;
year, month, day := fromDate.Date()
The time type also has Date() method which returns the year, month and day of the time in single call.
With the accepted method, if you need the month number you can simply cast the Month object to int since it's an enum:
year, month, day := time.Now().Date()
log.Printf("%v-%v-%v", year, int(month), day)

LastFullWeek starting with monday in crystal reports

When using LastFullWeek i get the last Sunday - Saturday week, but for my reports i want the last Monday - Sunday week.
Is there any simple way to get this behaviour, or do I have to write my own function for it (which isn't that hard, but unconvenient for such a common date span.)
custom function:
//LastFullWeekEx
Function (DateVar date, Optional NumberVar firstDayOfWeek := crSunday)
(date - DayOfWeek(date, firstDayOfWeek)) - 6 TO (date - DayOfWeek(date, firstDayOfWeek))
usage:
// use with non-volatile DataDate and Sunday
{TABLE.DATE} IN LastFullWeekEx(DataDate)
// use with non-volatile DataDate and Monday
{TABLE.DATE} IN LastFullWeekEx(DataDate, crMonday)
testing:
// should return True
( Minimum(LastFullWeek) = Minimum(LastFullWeekEx(DataDate, crSunday)) ) AND
( Maximum(LastFullWeek) = Maximum(LastFullWeekEx(DataDate, crSunday)) )
Instead of using
{DATE} in LastFullWeek
use the form
{DATE}-1 in LastFullWeek
The code, if no better answer comes along, for others who find this question through the search engine:
{DATE} >= currentdate - dayofweek(currentdate, crMonday) - 6 AND
{DATE} < currentdate - dayofweek(currentdate, crMonday) + 1
You have no other choice than to use a custom formule as Crystal Reports uses fixed week settings (US). So a week is Sunday to Saturday and DayOfWeek starts with Sunday (value/index 1).
Add +1 to LastFullWeek min and max:
DateVar Start := Minimum(LastFullWeek)+1; //Monday
DateVar End := Maximum(LastFullWeek)+1; //Sunday
Edit: Since LastFullWeek always takes Sunday as the first day of the week, we need to check if the current day is Sunday. If so, we need to subtract a week:
// Check if the current day is Sunday
IF (DAYOFWEEK(CurrentDate) = 1)
THEN (
Start := Start - 7;
End := End - 7
);
Example: Date range to string
StringVar LastWeekRange := ToText(Start) + " - " + ToText(End);
LastWeekRange;
Return example: "MM/DD/YYYY - MM/DD/YYYY"
Example: Selecting all dates within date range
{datefield} >= Start and {datefield} <= End;

Groovy get today's date at minute 00:00:00

I have this problem. I need to do the following:
get todays date
make a new date which will be today's date at 00:00:00
make another date which will be today's date at 23:59:59
For example. Today Date is 12-January-2012 19:00
How can i make a new date, which will be 12-January-2012 00:00 (the start of the current day)
It may seems easy, but i couldnt find any groovyway to get it, any help would be apreciated.
To get the date at midnight use Date.clearTime (docs):
dateAtMidnight = new Date()
dateAtMidnight.clearTime()
(Javadocs are for Groovy JDK < 2.0, clearTime() is declared void in Groovy JDK 2.0, preventing d = new Date().clearTime(). Comments indicate the original functionality may be restored, yay!)
For the comparison, instead of using <= 23:59:59, use < (the next day):
(aDate >= dateAtMidnight) && (aDate < (dateAtMidnight + 1))
An alternative way, but it sets the datetime (but it doesn't get the date merely)
dateAtMidnight = new Date()
dateAtMidnight.set(hourOfDay: 0, minute: 0, second: 0)