How to Insert Javascript function between sql query? - javascript

Is there any way to insert java-script function between the query ??
For example :: In an query, i have stored date of birth like this 10101990 in the database, it means 10/10/1990, but I have display it in-front of page but in certain format like 10.10.1990 by using one java-script function.
Please suggest me any way ??

You should not be storing date as a string on the database. This might have a lot of issues. You have to store date as, well, a Date
You have to fetch this using a query using a language like Java or PHP.
When you get the date in the screen, you can format it in javascript, if required. However you can format it in PHP or Java. For java see SimpleDateformat.
See also this question.

You can manipulate with data values in jquery6 just before display it like this

Related

AJAX jQuery. Pulling a Date & Time field from a SharePoint List. Why is it displaying in a funky format?

So I am pulling information from different SharePoint lists across a site to a single landing page. One of the fields I am pulling through to display on the html table is a Date & Time field (Date Submitted) is the column name. When it populates to the HTML table like I want it to, there is only one issue, the date is formatted like so: 2020-07-01T04:00:00Z.
I know a quick fix would be to just make the field a single line of text field and have the user manually enter the date, but for user experience I would much rather have it be a Date & Time field for the functionality, but this is when the formatting issues arise.
How do I get it to return so it is formatted like yyyy/mm/dd? Any advice would be appreciated
The format you ran across is standardized, it's called the ISO 8601 format. If you want the date to be in another format, you should use some sort of conversion mechanism.
I'd recommend moment.js, which would let you parse and format in just about any way that you'd like:
moment('2020-07-01T04:00:00Z').format('YYYY/MM/DD');

Using Javascript within Splinter to change a value for an element of known ID

I am quite new to python. I'm trying to extract data from a website and I need to set dates for a data search. The dates are set via date pickers and I cannot fill the forms using splinter element.fill(). However, I know the element names and the date is stored as its value which should be changeable.
Since I've never used javascript I'm not sure what the syntax is. I hoped something like:
browser.execute_script("document.getElementById('fromdate').value=10.12.2019")
would work, but I run into issues. Could somebody offer some help?
Yes, I think this code should work, but I think you missed the quotes. Please try something like this:
browser.execute_script('document.getElementById("fromdate").value="10.12.2019"')

How to save the current date/time when I add new value to Firebase Realtime Database in JavaScript

I want to add data in firebase database using webpage.
For unique id I want to use date and time like below format
MTB + yyyyddmmhhmmss
MTB20190517083578
How to do this? Please tell me any one.
I strongly recommend you to use moment.js wich handles a lot of weird Date behaviours (like non UTC dates and formatting).
If you use moment you can format the date using:
moment().format('MTBYYYYMMDDhhmmss')

Converting to localtime at client with c#

I have a database with records stored in UTC. The c# .NET application reads the data and populates a *.cshtml table server-side. The server doesn't know the client's timezone as it is not a parameter reported by the browser, and there is no login or user form for the user to enter a profile and declare their timezone. The result is a table displayed in UTC at the browser.
I am aware that if the value is in a javascript variable then it is trivial to get the browser to make timezone offset adjustment. However, the data reaches the browser as a set of TD tags with text between.
Any solution I can think of to convert this to local time is inelegant - using javascript to walk through the table, get the innerHTML, parse it, adjust it, and put it back. That feels like an awful solution. Is there a better way? Pass the data as a JSON object and dynamically create the table via javascript? again it feels unwieldy. Is there a simpler way to make the browser take the values between the TD> tags and adjust, like
<TD> onsomething="this.innerHTML=adjustTime("2017-06-17 09:00:00");> </TD>
or a better way?
A general rule when dealing with times in different zones is to store & transmit the value in UTC and then allow the 'view' to display it as appropriate i.e. in the users current timezone.
I would add an API that provides a list of times in UTC, then allow the javascript client to render and display them as appropriate

Proper way of formatting date/time for MySQL and for View vice versa

I use backbone with Laravel.
I have several fields in a form with date and time ('dd-mm-yyyy', 'hh:mm').
When I want to save the form I use my own function to convert it for MySQL ('yyyy-mm-dd', 'H:i:s') via date() which I added to save() in Laravel Model Class.
But vice versa is harder because there is no single function in Laravel for data output.
find(), findOrNew(), findOrFail(), ... - there are in different classes so I cant use single place to add the formatting function.
In this case I even tried to format date in frontend which seems bad practice.
So what way should I use?
Is there any another way to format this date/time?
If the programming environment you are using expects (or can handle) date strings in a certain format, you could just use MySQL functions to construct the string as needed, such as DATE_FORMAT().
I would not recommend using these functions to convert your date fields to programming environment format in WHERE, ON, or HAVING clauses though. For one, it would then be using string comparison, for another (and more importantly) it defeats any indexing benefits you might have for those fields.

Categories

Resources