Increment the date by Minutes

Hi,

I want to increment the date by minutes.
I have declared the date as follows

Dim d As New Date
d.Year = 2013
d.Month = 01
d.Day = 01
d.Hour = 00
d.Minute = 00
d.Second = 00

I want to increase the minute by 1 , when the minutes came to 60 , the hour was changed to 1 , when the hour came to 24 , the date become 2.

I don’t know how to proceed further. Help me out from this.

If you do:

d.Minute = d.Minute + 1

60 times, you’ll see that d.Hour is 1.

Safer to increment TotalSeconds by 60.

[quote=209888:@Marco Hof]If you do:

d.Minute = d.Minute + 1

60 times, you’ll see that d.Hour is 1.[/quote]

Thanks…

I have stored the value as

Dim TimeStamp As Date
d.Minute = d.Minute + 1
TimeStamp = d.SQLDateTime

While run , i have received the error as Expected class date but got string.

Advice how to convert the string as date

d.SQLDateTime returns a String and your trying to assign it to a date.

Dim str as String
d.Minute = d.Minute + 1
str = d.SQLDateTime

Safer? In what way?

[quote=209923:@Albin Kiland]d.SQLDateTime returns a String and your trying to assign it to a date.

Dim str as String d.Minute = d.Minute + 1 str = d.SQLDateTime [/quote]

I want the output as date format…
Is there any solition to convert the SQLDatetime to date?

I don’t understand. It is a date already. What do you need it to be?

An example.

If you do

Dim d As New Date
d.Year = 2013
d.Month = 01
d.Day = 01
d.Hour = 00
d.Minute = 00
d.Second = 00

Then “d” will be 2013/01/01 00.00.00.

Then when you do

d.Minute = d.Minute + 1

You’re adding a minute to the already existing date so “d” will now be 2013/01/01 00.01.00.

PS.
Your code can be shortened a bit by passing values to the constructor…if I’m not wrong :slight_smile:

Dim d As New Date (2013, 1, 1, 0, 0, 0)

I’ve heard that too and that is how I do it. Don’t remember why though :slight_smile:

[quote=209922:@Manikandan Karuppaiah]Thanks…

I have stored the value as

Dim TimeStamp As Date
d.Minute = d.Minute + 1
TimeStamp = d.SQLDateTime

While run , i have received the error as Expected class date but got string.

Advice how to convert the string as date[/quote]
Try:

Dim TImeStamp as new date
d.minute = d.minute + 1
TimeStamp.sqlDateTime = d.sqlDateTime

Once upon a time there were bugs that gave you improper results if you used anything other than TotalSeconds. IIRC, the bug was on Windows and happened when you decremented one of the other values.

I don’t know if those bugs have been squashed, but I still consider it “safer” to use TotalSeconds especially since it doesn’t cost more than a few keystrokes.

I have created a Time class that works similarly to the Date class but is just for manipulating Hours/Minutes/Seconds. It is free to the Xojo community.

You can download it here - Time Class.

For completeness, this is how you would do it using Xojo.Core.Date:

Dim origDate As New Xojo.Core.Date(2013, 1, 1, 0, 0, 0, 0, Xojo.Core.TimeZone.Current) Dim minuteInterval As New xojo.Core.DateInterval(0, 0, 0, 0, 1) Dim newDate As Xojo.Core.Date = origDate + minuteInterval