Last day of month

Issues related to label design (working with databases, data processing, RFID encoding etc.) and printing (from NiceLabel Express, NiceLabel Pro, NiceForm and NicePrint)

Moderators: Georges, milos, NiceLabel Support Team

Post Reply
KLewisMFL
Newcomer
Posts: 2
Joined: Mon Oct 14, 2013 12:49 pm

Last day of month

Post by KLewisMFL » Fri Dec 15, 2017 9:43 am

Hi All,

I'm looking at putting a variable in that allows the person printing to input month/year and the result would be the label will show the date which includes the last day of the month. Is it possible?

Thanks

User avatar
Saso
NiceLabel
NiceLabel
Posts: 2988
Joined: Mon Sep 04, 2006 8:09 am
Contact:

Re: Last day of month

Post by Saso » Fri Dec 15, 2017 2:17 pm

This is possible with VBScript oneliner.

Code: Select all

Result = DateAdd("m", 1, DateSerial(Year(Date), Month(Date), 1)) - 1
Where:
  • Date is the variable with selected date (just month & year are used from it)
  • DateSerial() is a function that converts provided values into date object
  • DateAdd() is a function that adds time to date variable.
The script does the following:
  • Takes year and month from the selected date. This is Year(Date) and Month(Date) part.
  • Creates a date object - 1st day in the selected month/year. This is DateSerial() part.
  • Adds one month. This is DateAdd() part.
  • Substract one day.
The result is last day in the selected month.
See the attached label.
screenshot.png
screenshot.png (14.35 KiB) Viewed 2426 times
Attachments
last day in month.nlbl
(3.32 KiB) Downloaded 213 times
Saso Fleiser
Senior Technical Product Specialist

KLewisMFL
Newcomer
Posts: 2
Joined: Mon Oct 14, 2013 12:49 pm

Re: Last day of month

Post by KLewisMFL » Mon Dec 18, 2017 10:43 am

Hey Saso,

Thanks for that!

Post Reply