Operator_Convert using DateTime object

I had subclassed the Date object and written some Operator_Convert methods so that I could assign a date object from a string with just the = sign (and a couple other types)

In converting my code, I see that I have hundreds of places to change if I cannot figure out how to make this work.

In my subclassed object, I could parse the string and then set TotalSeconds based on another internal Date object created or setting individual items such as Year Month and Day.

So now my question is, can you change the datetime object (within a subclass) like you could in the date object. Or is the only way to “Change the date” is to assign it another datetime object outside of the object code.

You can “change the date” by making it a New Datetime object. Then, subclassing should also work but I would suggest to look at the functionality. There is a FromString method that you may want to take advantage of, instead of custom code.

I was more asking is there a direct replacement for my Operator_Convert method so I can change just my sub class and not all the code that uses it.

So no good answer for my hundreds of lines of code that say basically the following:

Dim dt as new DateSubclass

dt = “05/10/2020”

or

dt.Month = dt.Month + 1

I would need to change them to:

Dim dt as DateTimeSubClass

dt = DateTime.FromString(“05/10/2020”)

and use the DateInterval function (outside of the object) for my second example.

Right?

Right. Note that you can use the US date format if you specify the locale. Otherwise, you must use the SQLDate format (YYYY-MM-DD)

All the details are here.

Thank you for the quick reply. Hoping for an easier / quicker change. Lots of projects and code to go through…

Are these “convert from” or “convert to” versions of operator_convert ?
A convert from would be like

    Operator_convert( fromValue as string)

These are basically a special form of Constructor so you dont actually return anything in any case
But you DO have a new instance that is uninitialized
Since datetime is immutable you may have difficulty altering this instance as even adding a date interval returns a new instance

A convert to would look like

    Operator_convert() as string

I haven’t tried it, but I suppose you could change your class from being a subclass of datetime to it’s own type that holds a private property of type datetime and then pass through the properties and methods and such to that object. That should let you maniuplate the datetime property within an operator_convert() so you would only have to tweak your code in that one operator_convert method.

If that works, I’m sure it’s not best programming practice but it should address your problem.