Python or VBS code for soonest date?

Software technical issues not related to any of the other categories

Moderators: Georges, milos, NiceLabel Support Team

Post Reply
Kyle4Prez
Newcomer
Posts: 1
Joined: Tue Jun 01, 2021 6:16 pm

Python or VBS code for soonest date?

Post by Kyle4Prez » Tue Jun 01, 2021 6:22 pm

Can someone help me write a code to calculate the soonest date of two variables? At print, I will scan two date barcodes. I have created two date variables for this already. I would like a function that is able to determine which of these two barcodes has the earlier date, and then display that date. Example:
First barcode contains the date: 2023-01-03
Second barcode contains the date: 2022-12-30
I would like a function that takes these two variables then displays the date: 2022-12-30

Thanks

User avatar
Mytch
NiceLabel Support
NiceLabel Support
Posts: 212
Joined: Fri Jul 13, 2018 10:26 pm
Location: Milwaukee, Wisconsin
Contact:

Re: Python or VBS code for soonest date?

Post by Mytch » Wed Jun 02, 2021 11:40 pm

Kyle4Prez,

Normally I would recommend something in Python... but VBScript is just a lot easier for this scenario:

Code: Select all

If [date1] > [date2] Then
Result = [date2]
Else If [date2] > [date1] Then
Result = [date1]
Else
Result = "Something is broken"
End If
End If
[date1] and [date2] are the Date Variables in NiceLabel that can be inserted into the script. I'm sure there's a few ways to do this, but this should work just fine and syntax is clear enough. Hope it helps.

Mytch

Post Reply