determining if a new week in coldfusion - date

I need to determine if a set of dates contain two different weeks.
For example:
When returning a set of records from a database that contain a date, there needs to be something to distinguish between the different weeks.
<cfloop query="datesExample">
<cfif DateDiff("d",DateFormat(lastDate),DateFormat(OriginalDate)) GTE 7>
<hr />
</cfif>
<p>#OrginalDate#</p>
<cfset lastDate = DateFormat(OrginalDate) />
</cfloop>
To me, this seems like all the logic I'd need to add to determine if there is a new week.
Although, I'm not getting any results from this.
Anyone have an ideas?
Update:
This is my actual if statement:
<cfif DayofWeek(lastShiftDate) NEQ DayOfWeek(Time_In) AND DateDiff("d",lastShiftDate, Time_In) GTE 7>

I would QueryAddColumn to add an additional column onto the end of your query, then loop through and set the start of the week for each record in the query. Something like this:
<cfset datesExample = QueryNew("lastshiftdate", "date") />
<cfset QueryAddRow(datesExample) />
<cfset QuerySetCell(datesExample, "lastshiftdate", "2009-01-15") />
<cfset QueryAddRow(datesExample) />
<cfset QuerySetCell(datesExample, "lastshiftdate", "2009-01-20") />
<cfset QueryAddColumn(datesExample, "StartofWeek", "time", ArrayNew(1)) />
<cfloop query="datesExample">
<cfset QuerySetCell(datesExample, "StartofWeek", DateAdd("d", -(DayOfWeek(lastshiftdate) - 1), lastshiftdate), CurrentRow) />
</cfloop>
<cfdump var="#datesExample#">
Then when you use the cfoutput, you can just group by the StartofWeek column without doing all of the goofy conditional logic.
Dan

when the dayofweek of dateA is different than dayofweek of dateB , and their DateDiff is larger than 7?
Then dateA and dateB are in different week?

The code you presented has several syntax errors. If you copied it from your source, you might try turning off whatever error trapping is keeping you from seeing the errors.
First, to address syntax:
Your cfif is not closed. DateFormat() takes two arguments -- the date object and the date mask. If this is not in a cfoutput block, you'll just display the literal #OrginalDate#.
To address the logic:
I'm assuming OriginalDate is a field in the query return.
I'm not sure exactly what you are trying to do. Your code would print a horizontal line instead of the date anytime there was more than 6 days between two records. However, you will never print a horizontal line as long as the dates are closer together. So, if you had ever Mon/Wed/Fri in the database, you would never get an HR, because the datediff would be two or three days, never seven.
There are several approaches to deal with this. If you clarify your purpose, we might be able to help you better. For example, what defines a new week? Sat/Sun at midnight? Since the first date in the query? What are you trying to display?

Check out the Day of Week function

Check out the Week function: From a date/time object, determines the week number within the year.

It was much more simple than what I thought. All I had to do was get the value of the first date. So, <cfif query.RecordCount EQ 1><cfset firstDate = Now() /></cfif> and then do a dateDiff() with the lastShiftDate
Thanks for everyone's help.

Related

How can one disable future dates from the current date and also disable dates 1 month before the current date using Blazor?

Using Blazor date input how can you disable future dates from the current date and also disable dates 1 month or more before the current date? But display the current date when page loads.
I'm using Blazor-Server-Side.
So far I have the razor page set like this:
<InputDate #bind-Value="viewmodel.Date" class="form-control" id="date"></InputDate>
<label> The date </label>
<ValidationMessage For="() => viewmodel.Date" />
And the model like this:
[Required(ErrorMessage = "Select the date")]
public DateTime Date { get; set; } = DateTime.Now;
I have tried 'max' attribute in the input tag to leave an end date but it did not work. I could not find a method to do this. Please let me know how I can solve this in Balzor or if there are other ways to achieve the same results? I would prefer if no jquery was used.
Thanks for your help.
If you are happy to do it in the markup, you can use min and max
<input type="date" min="2021-11-01" max="2022-01-31"/>
This example restricts to dates between 1st November 2021 and 31st Jan 2022 - the format yyyy-MM-dd is important in min/max.
You can use variables for the dates in Blazor, but make sure to format them using yyyy-MM-dd.
<InputDate #bind-Value="viewmodel.Date"
class="form-control"
id="date"
min=#DateTime.Today.AddMonths(-1).ToString("yyyy'-'MM'-'dd")
max=#DateTime.Today.ToString("yyyy'-'MM'-'dd")
/>
Blazor Repl - Working Sample

Dijit DateTextBox set date in a year lower thatn 100

I am trying to set an really old value in a DateTextBox. Unfortunately the widget won't accept dates set in a year lower than '100'.
When I try to set the value of the element to 0017-01-01 the widget automatically sets itself to 2017-01-01.
The displayed value property keeps unchanged until the widget gets out of focus, then it is changed to the internal date.
<input type="date"
data-dojo-type="dijit/form/DateTextBox"
value='0017-01-01'
id="myDate" />
Is there any way to allow older dates 0100-01-01 in the DateTextBox?
I also build a small jsfiddle to demonstrate the effect:
http://fiddle.jshell.net/shfe1oqs/
You can add the constraint strict == true to your DateTextBox:
<input type="date" data-dojo-type="dijit/form/DateTextBox"
data-dojo-props="constraints: {strict: true}" value='0017-01-01' id="myDate" />
The modified jsfiddle: http://fiddle.jshell.net/fuzxt1fb/3/
Note that then you will have to enter two digits values for day and month

Angular 2 Date Pipe handling offset when none exists

I have some code that processes a date string and I want to display it on the UI using the date pipe. Here is a sample value of the date
"2017-02-07T21:23:19.163"
And here is the template code
<div class="input-group" *ngFor="let history of selectedPricingItem.history">
<span class="input-group-addon">
<i class="fa fa-fw fa-calendar-o " aria-hidden="true">
</i>
{{history.createdDate| date:short}}
</span>
<textarea class="form-control" [(ngModel)]="history.generalNotes" rows="2" readonly></textarea>
</div>
Here is date that is put on the UI
2/7/2017, 5:23 PM
For some reason it is adding an offset when there is no offset in the string. Do I need to convert it to a date object with moment or something first?
I am using "#angular/common": "^2.2.0" in my package.json
This happens b/c DatePipe expects the supplied date to already have a timezone offset, and if none is specified then it assumes that the offset is "+0" (UTC). It then attempts to convert the date to the client's local offset. You must be UTC-6 (Central Time), hence why it's subtracting 6 hours. Someone on Eastern or Pacific time would see a different time than what you see.
Not sure what backend you're using, but mine is C#/WebApi, and my solution was to find DateTime objects where the Kind property equals "UnSpecified" and change it to either "UTC" or "Local", as appropriate, that way the date gets JSON-serialized with a timezone offset and eliminates confusion.
An alternative solution if you don't like this behavior is to replace DatePipe with your own custom pipe and use something like moment.js to handle the date parsing (DatePipe uses the Internationalization API by default).

How can I suppress the time from date time field in TFS query results?

Any idea how to suppress the time from showing up in query results? They are making my reports look cluttered. My custom field "Due Date" has unnecessary the 12:00:00. I can live with it on the "Created Date" field
You can set the field xml like the below example:
<Control
FieldName="Support.TimeReceived"
Type="DateTimeControl"
Label="Time Received:"
LabelPosition="Left"
Format="Custom"
CustomFormat="dd/MM/yyyy HH:mm:ss" />
please refer to the detailed solution in this article: http://nickhoggard.wordpress.com/2010/07/18/custom-date-format-for-the-work-item-datetimecontrol-tfs2010/.

Validate range of dates with Regula

Is there any way to use #Range to validate a range of dates in Regula? (ditto #Min and #Max)
Or do I need to use #Custom?
#Range(min=
and
#Range(max=
do not seem to accept anything of the type Date - only numbers or strings.
Unfortunately #Range only accepts numbers. I think you can do something like this though:
<input type="hidden"
name="date"
id="date"
data-constraints="
#Future(date='2000/1/1', format='YMD')
#Past(date='2010/1/1', format='YMD')"
/>
This ensures that the date is after 2000/1/1 and before 2010/1/1 (i.e., in between). I didn't document the date parameter because I don't think I had implemented it when I wrote the documentation. Sorry; the documentation is a bit behind because I'm working on rolling version 1.3 of Regula out, that will have a lot more goodies. I'll be getting started on updating the documentation soon!
I found that the following hack works:
I added a second, hidden input that contains the date entered in the format of Date.getTime():
<input type="hidden" data-bind="value: myDateValue.getTime()" ... />
(I'm using Kendo MVVM, but I'm sure other MVVM libraries can handle the same approach)
Then for the constraint, on server side (ASP.NET MVC in my case) I'm generating the Unix time for the min and max:
#Range(min="<%= (dateTime1 - new DateTime(1970, 1, 1).ToLocalTime()).TotalSeconds %>",
max="<%= (dateTime2 - new DateTime(1970, 1, 1).ToLocalTime()).TotalSeconds %>")
EDIT
Need to use .TotalMilliseconds - and even so there's some unexplained discrepancy.