Example Code

SORTING DATE "MONTH/DAY/YEAR"

Code and Documents

Attachment

Overview

 

SORTS DATE ARRAY (STRING DATA TYPE)

 

 

 

Description

 

This VI will sort the Array of Dates in Ascending order and the Format of date is as Follows "MONTH/DAY/YEAR" in an String array

 

Hardware and Software Requirements

 

No Hardware's required

LabVIEW Version above LV2015

 

Steps to Implement or Execute Code

 

 

1. Open the VI

2. Feed Date info in the Date input Node in different order

3. Run the VI

4. Now you find the sorted DATE Array

 

Additional Information or References

 

----------------------------------------------------------------------------------------------------------------
Palanivel Thiruvenkadam | பழனிவேல் திருவெங்கடம்
LabVIEW™ Champion |Certified LabVIEW™ Architect |Certified TestStand Developer

Kidlin's Law -If you can write the problem down clearly then the matter is half solved.
-----------------------------------------------------------------------------------------------------------------

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Comments
croohcifer
Member
Member
on

A few thoughts:

 

1.  Because of the conversion through the timestamp datatype, the code breaks for any dates before 01/01/1904, as seen below.  I would add some error handling that throws an error if the user adds too early a date.  This is probably not a problem for most people doing data acquisition today, but it's worth noting. 

Capture2.PNG

2.  The sorted date output also doesn't zero-pad the single-digit days and months (and it removes it if you have it on the inputs), which could be annoying if you're then going to append this date string to a file path and want those files to appear in date-order on disk.

Capture.PNG

3.  If you can enforce zero padding for the month, date, and year - i.e., Jan 1, 1 would have to come in as 01/01/0001, not 1/1/1, and Feb 20, 2099 would have to come in as 02/20/2099, not 2/20/2099 - then your code can be simplified to the snippet below and would support sorting any dates from 01/01/0000 AD to 12/31/9999 AD.

Very Simplified Time Sorting.png

4.  If you can't or don't want to enforce zero padding on the inputs but DO want zero padding on the outputs, you could simplify the code to the snippet below and still get the same supported date ranges as in #3.

Simplified Time Sorting.png

 

Cheers,

David

Contributors