LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Time Stamp

I have two inputs of time stamp control "from" which is a starting date, and "to" which is an ending date I want to list out the dates which will lie between them. Can anyone give me some snippet or algorithm through which we can list out the dates?

0 Kudos
Message 1 of 8
(588 Views)

Very brutal solution, but it works. If this is what you want.

I'm sure there are some edge cases that you should check (leap seconds and leap days maybe?).

 

Dates.png

Basjong53_0-1726146239027.png

 

Message 2 of 8
(564 Views)

Hi sesinfo,

 


@sesinfo wrote:

I have two inputs of time stamp control "from" which is a starting date, and "to" which is an ending date I want to list out the dates which will lie between them. Can anyone give me some snippet or algorithm through which we can list out the dates?


  • Why don't you create the VI on your own?
  • How do you define "dates"?
  • Should the result include or exclude the start/end date? (Because you ask for "in between"…)

What have you tried and where are you stuck?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 3 of 8
(563 Views)

Start with the first date and continuously add 86400 (seconds/day) to get each day until you are past the last date.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 4 of 8
(562 Views)

@Basjong53 wrote:

Very brutal solution, but it works. If this is what you want.

I'm sure there are some edge cases that you should check (leap seconds and leap days maybe?).

 

Dates.png

Basjong53_0-1726146239027.png

 


That won't always work due to Daylight Saving switchovers.

0 Kudos
Message 5 of 8
(482 Views)

@paul_a_cardinale wrote:

@Basjong53 wrote:

Very brutal solution, but it works. If this is what you want.

I'm sure there are some edge cases that you should check (leap seconds and leap days maybe?).

 

Dates.png

Basjong53_0-1726146239027.png

 


That won't always work due to Daylight Saving switchovers.


That's why I just tell ChatGPT to do it for me in python, then call a python node 😂  
Aint no body got time to think about that

from datetime import datetime, timedelta
import pytz

def list_dates_between(start_date, end_date, timezone_str='UTC'):
# Set the timezone using pytz
timezone = pytz.timezone(timezone_str)

# Ensure the start and end dates are timezone aware
start_date = timezone.localize(start_date)
end_date = timezone.localize(end_date)

# List to store the dates between the two timestamps
date_list = []

# Loop through each day and append to the list
current_date = start_date
while current_date <= end_date:
date_list.append(current_date)
current_date += timedelta(days=1)

# Return the list of dates
return date_list

# Example usage:
start_date = datetime(2024, 3, 10, 0, 0) # Day before daylight savings in US
end_date = datetime(2024, 3, 15, 0, 0) # Day after daylight savings starts
timezone_str = 'US/Eastern'

dates = list_dates_between(start_date, end_date, timezone_str)
for date in dates:
print(date.strftime('%Y-%m-%d %H:%M:%S %Z%z'))

CLA
Message 6 of 8
(456 Views)

@UnholyPenguin wrote:

@paul_a_cardinale wrote:

@Basjong53 wrote:

Very brutal solution, but it works. If this is what you want.

I'm sure there are some edge cases that you should check (leap seconds and leap days maybe?).

 

Dates.png

Basjong53_0-1726146239027.png

 


That won't always work due to Daylight Saving switchovers.


That's why I just tell ChatGPT to do it for me in python, then call a python node 😂  
Aint no body got time to think about that

from datetime import datetime, timedelta
import pytz

def list_dates_between(start_date, end_date, timezone_str='UTC'):
# Set the timezone using pytz
timezone = pytz.timezone(timezone_str)

# Ensure the start and end dates are timezone aware
start_date = timezone.localize(start_date)
end_date = timezone.localize(end_date)

# List to store the dates between the two timestamps
date_list = []

# Loop through each day and append to the list
current_date = start_date
while current_date <= end_date:
date_list.append(current_date)
current_date += timedelta(days=1)

# Return the list of dates
return date_list

# Example usage:
start_date = datetime(2024, 3, 10, 0, 0) # Day before daylight savings in US
end_date = datetime(2024, 3, 15, 0, 0) # Day after daylight savings starts
timezone_str = 'US/Eastern'

dates = list_dates_between(start_date, end_date, timezone_str)
for date in dates:
print(date.strftime('%Y-%m-%d %H:%M:%S %Z%z'))


I don't trust deranged bots.  Here's how I would do it:

ds.png

Message 7 of 8
(441 Views)

Just for fun, here are a couple of other ways. I haven't checked if they handle DST transitions correctly.:

  1. When you add a double to a timestamp, you can set the unit of the double to be d. This will add days, so you can now just add N days.
  2. If you convert the timestamp to a time cluster, you can set values >31 in the day of month element. When you convert the cluster back to a timestamp, it calculates the date based on that number.

AddDays.png


___________________
Try to take over the world!
Message 8 of 8
(352 Views)