Converting ASP.NET Razor C# code to TypeScript/JavaScript for working with SqlDateTime types

Currently, I am in the process of converting an older .cshtml view file into pure HTML + TypeScript with the help of Angular1. The focus here is not so much on Angular, but on finding equivalent functionality in TypeScript (or JavaScript) to replace some C# code within a Razor view.

The original code snippet looked like this:

ng-init="
vm.defaultStartDate='@SqlDateTime.MinValue.Value'; vm.defaultEndDate='@SqlDateTime.MaxValue.Value'"

In the updated version, these values will no longer be set directly in the view. Instead, the Angular controller logic written in TypeScript can handle the initialization and usage of these values when needed. However, I am struggling to find the correct implementation in TypeScript/JavaScript.

According to MSDN, @SqlDateTime.MinValue.Value corresponds to:

The minimum valid date for a SqlDateTime structure is January 1, 1753

Similarly, from the MSDN page for @SqlDateTime.MaxValue.Value:

The maximum valid date for a SqlDateTime structure is December 31, 9999.

I have attempted the following approach, but encountered issues on the server indicating that the dates are not defined correctly. When debugging in TypeScript, I observed discrepancies from the original versions as well.

this.defaultStartDate = String(new Date('1/1/1753'));
this.defaultEndDate = String(new Date('12/31/9999'));

I believe there must be a more efficient way to initialize these dates, and I suspect I am overlooking something simple. What would be the optimal method to define these dates using TypeScript/JavaScript to mimic the default start/end dates initialized by the previous C# code?

Answer №1

To properly format your date, you have two options: convert it to yyyy-mm-dd or use the client variant. For detailed instructions, please check out the link provided below.

Convert DateTime to string format("yyyyMMdd")

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What steps should I take to make my include function operational?

As I develop a website for our entertainment company, I encounter language translation issues. Due to our diverse clientele, I implemented a multilingual feature on the site. However, during testing, all the text appeared blank. I suspect that the root of ...

Utilizing Jquery to locate a link inside a Div and displaying it as specified in the HTML

Looking for a solution to make div elements clickable as links? The usual methods involving window.location or window.open may not be suitable if you have numerous divs with predefined targets. If you're not well-versed in Javascript, finding the righ ...

When a button in a React list is clicked, the event always returns a reference to the last element

I am facing an issue with retrieving the selected item from an array of elements. I have an API service that returns a list of 5 jobs, and a React page to display the applicants. The table rendered from the list has a menu button for each row. When I click ...

Switch to using addresses instead of latitude and longitude coordinates when utilizing the Google Maps API

I am looking to utilize Google Map Markers to indicate the locations where our services are offered. The code I have created using latitude and longitude is functioning properly, however, for my project I need to display city names instead of lat/long ...

Problem with displaying legends in a stacked bar chart using jqplot

I am encountering a problem with the legend placement on the jqplot stacked bar chart. I want to customize the positioning of the legend, but my changes are not taking effect. What I desire is this: However, what I am currently seeing in the legend is as ...

The checkbox header template for the 'CheckAllCB' in ASP.NET is not functioning as expected

In my server-side coding using Visual Studio 2005 C#, I have encountered an issue with a checkbox template in my gridview. I attempted to use a CheckAllCB button outside the gridview to check all checkboxes in the item template upon clicking, but it does n ...

Error encountered when trying to save Mongoose model - "Cannot use $inc on a non-numeric value"

Currently, I have set up 2 mongoose models in separate files. const userSchema = new mongoose.Schema({ name:{type: String, required: true}, postHistory:[{type: mongoose.Schema.Types.ObjectId, ref: "Posts"}] )}; module.exports = mongoose.model(&q ...

Is it possible to trigger a submit button to perform a POST request and an AJAX call simultaneously

I have a form that sends a POST request to show_aht2.php, but I also need it to trigger an AJAX call as shown in the code below. How can I achieve this without redirecting the user to another page? I want the user to remain on map.php. Thank you in advanc ...

Back from where it came, the return function appears unable to escape the confines of the code

Currently, I am working on solving some leetcode problems and stumbled upon an interesting issue in my code for the problem at . However, I am having trouble understanding how it actually functions. The problem with this code lies in the fact that the ret ...

Disparity in response status codes during an ajax call from both client and server

Scenario: - Node/Express/Angular 1.x Issue - The client always receives a response code of 200 over the ajax call, even when the server response headers indicate 304 or 200 (confirmed in the server console and browser network response headers). What is th ...

creating an HTML table from JSON data using a specific key

In this json file, I am looking to create separate tables based on the IDs provided. For example, ID: "50" should be displayed in one table, while ID: "57" should be shown in another table within the same context. { "version": "5.2", "user_type": ...

Looking for assistance with JQuery and JavaScript?

I oversee a team of employees, each with a 7-day work schedule. To streamline the process, I have developed a PHP form that I would like to use to collect data for verification in JavaScript before submitting it to an SQL database using AJAX. My main cha ...

Changing integers and floating point numbers to three decimal places

Here is my objective: If a double field contains more than three decimal places, it should be converted to three decimal places. If there are no decimal places present, it should be converted to three decimals. For example: 12.878999 -> 12.878 120 -&g ...

Converting an Angular1 App into a VueJs app: A step-by-step guide

Let's dive right in: I'm embarking on the journey of revamping an app that originally utilized Angular 1, but this time around I'll be harnessing the power of VueJS 2. As someone unfamiliar with Angular 1, I'm faced with some perplexing ...

Filter search results using selected region from dropdown menu

I have been attempting to retrieve the value from a dropdown list and customize the search functionality specifically for the selected field. The client should only be able to search within the chosen zone in the dropdown. I have been searching for a solut ...

Attempting to automate the process of clicking a button on a webpage using cefsharp

Hello, I am currently working with cefsharp and vb.net to develop a code that will help me navigate to the next page of a specific website. The website link is: https://www.recommendedagencies.com/search#{} My goal is to extract the list of company names ...

Is there a way to navigate to a specific div when clicking on it?

Need help with scrolling after running code function scrollFunction() { document.getElementById('insert').scrollIntoView(); } I have a button that triggers some code and I want the page to scroll afterwards. Currently, it scroll ...

What is the method for displaying specific text lines in italic format within the TextArea Tag in SAP Fiori Apps?

I need to format specific text lines in the "TextArea" tag of my SAP Fiori App in italic. The data for my text area is retrieved from a SAP OData Service as an Array. I am currently displaying the data using a loop and setting it as follows in my Java ...

What is the use of the mongoose $gt operator in an Express application built with

I am searching for users whose tokens have not yet expired. try { const user = await User.findOne({ resetToken: passwordToken, resetTokenExpiration: { $gt: Date.now() }, _id: userId, }); if (!user) { throw new NotFoundEr ...

Positioning Images at the Top of the Screen in React Native

I have two images that I would like to display side by side at the top of the screen. <View style={styles.container}> <View style={styles.topWrapper}> <Image source={TOP_START_GRAPHIC} style={styles.topStartImage} /> ...