I am using the following code to redirect visitors on my website:
<meta charset="UTF-8">
<meta http-equiv="refresh" content="1;url=http://mylink.com">
<script type="text/javascript">
window.location.href = "http://mylink.com"
</script>
I would like to add dates to the link so that the link becomes this:
"http://mylink.com/startdate=2016-01-09;enddate=2016-02-09"
I would also like to set the startdate parameter set to tomorrow's date and enddate parameter to be calculated based on the startdate value.
Thanks in advance!
Although JavaScript is not tagged in your question, I would do something like this:
function formatDate(date) {
var days = date.getDate();
var months = date.getMonth() + 1;
var fixedDays = (days < 10)? ("0" + days) : days;
var fixedMonths = (months < 10)? ("0" + months) : months;
var result = (1900 + date.getYear()) + "-"
+ fixedMonths + "-" + fixedDays;
return result;
}
function createLink(baseUrl, daysExpiration) {
var tomorrow = new Date();
tomorrow.setDate(tomorrow.getDate() + 1);
var expire = tomorrow;
expire.setDate(expire.getDate() + daysExpiration);
var result = baseUrl +
"/startdate=" + formatDate(tomorrow) +
";enddate=" + formatDate(expire);
return result;
}
var link = createLink("www.ex.com", 30);
window.location = link;
Here's a JSFiddle.
Related
So I figured out how to update the value of the database, but the another problem came up. When I'm trying to update the value of a certain in the table, the output is that it updated all the values. I'm not getting the correct key when a certain button is pressed for the update. Can you guys help me with this?
My .html file
var rootRef = firebase.database().ref().child("REPORTS").child('05-21-2017');
rootRef.on("child_added", function(snapshot){
var date = snapshot.child("dateAndTime").val();
var lat = snapshot.child("latitude").val();
var long = snapshot.child("longitude").val();
var link = snapshot.child("link").val();
var report = snapshot.child("report").val();
var status = snapshot.child("status").val();
var needs = snapshot.child("needs").val();
var key = snapshot.key;
console.log(key);
var updateData = "updateData()";
$("#table_body").append("<tr id='"+snapshot.key+"'><td>"+snapshot.key+"</td><td>" +date+"</td><td>"+report+"</td><td>"+lat+"</td><td>"+long+"</td><td>"+status+"</td><td>"+needs+"</td><td><button onclick = "+updateData+">update</button></td></tr>");
});
My .js file
function updateData(key) {
var rootRef = firebase.database().ref().child("REPORTS").child('05-21-2017');
rootRef.on("child_added", function(snapshot){
var rootRef2 = firebase.database().ref().child("REPORTS").child('05-21-2017/'+snapshot.key);
console.log(rootRef2);
rootRef2.update({status: "Ongoing"});
console.log("success");
});
}
Here is what my table looks like
I want to change a particular table when i click the update button. Please help me, badly needed.
const ulTable = document.getElementById('tabla');
//Create references
const dbRefObject = firebase.database().ref().child('Users');
//Sync table changes
dbRefObject.on('child_added', snap => {
var gear = snap.child('Gear').val();
var level = snap.child('Level').val();
var strength = snap.child('Strength').val();
$(ulTable).append("<tr id="+snap.key+"><td>" + gear + "</td><td>" + level + "</td><td>" + strength + "</td></tr>");
}); //child_added
dbRefObject.on('child_changed', snap => {
var gear = snap.child('Gear').val();
var level = snap.child('Level').val();
var strength = snap.child('Strength').val();
$("#"+snap.key).html("<td>" + gear + "</td><td>" + level + "</td><td>" + strenght + "</td>");
}); //child_changed
dbRefObject.on('child_removed', snap => {
var gear = snap.child('Gear').val();
var level = snap.child('Level').val();
var strength = snap.child('Strength').val();
$("#"+snap.key).html("<td>" + gear + "</td><td>" + level + "</td><td>" + strenght + "</td>").remove();
});
My DB is:
Users -> (Gear, Level, Strength)
I have a DataField with editable="true" and format mm/dd/yyyy. Then lets say user typed in month mm section 13 which is not correct. How can I validate it as well as dd section and yyyy section and show a pop up when it's incorrect?
Here is what happening when apply button was clicked:
var newDate:Date = dfDate.selectedDate;
var month:String = (newDate.month + 1) < 10 ? "0" + (newDate.month + 1).toString() : (newDate.month + 1).toString();
var date:String = newDate.date < 10 ? "0" + newDate.date.toString() : newDate.date.toString();
var year:Number = newDate.getFullYear();
var dateString:String = month + "/" + date + "/" + year;
Button section:
<mx:FormItem id="itemDate">
<mx:DateField id="dfDate" yearNavigationEnabled="true" editable="true"/>
</mx:FormItem>
You can use just a simple regular expression
var customRegExp:RegExp = new RegExp(/(0[1-9]|1[012])[\/](0[1-9]|[12][0-9]|3[01])[\/](19|20)\d\d/);
And then use .test function along with some formatting stuff
var fmt:DateFormatter = new DateFormatter();
fmt.formatString = "MM/DD/YYYY";
if(!customRegExp.test(fmt.format(dfDate.selectedDate)))
{
Alert.show("Please input date in format MM/DD/YYYY");
enableForm(true);
}
Worked for me just fine and I think will work for others as well!
Here is code all together:
var customRegExp:RegExp = new RegExp(/(0[1-9]|1[012])[\/](0[1-9]|[12][0-9]|3[01])[\/](19|20)\d\d/);
var fmt:DateFormatter = new DateFormatter();
fmt.formatString = "MM/DD/YYYY";
if(!customRegExp.test(fmt.format(dfDate.selectedDate)))
{
Alert.show("Please input date in format MM/DD/YYYY");
enableForm(true);
}
I am trying to create a new ActionScript 3.0 file in Flash that will include the Current Time, Date and Day of the week. I am able to complete the script separately (Time and Date) and (DayofWeek) but when combining I receive line errors 1120:Access of undefined property time. I am not a GURU but am a pretty fast learning. I would appreciate any help that can be provided to me. Also I would like for the time to display AM\PM and to show in double digits for numbers ranging from 1-9 with a "0" added. Thank you in advance
Here is my code below
var looper:Timer = new Timer(100);
looper.start();
looper.addEventListener(TimerEvent.TIMER, looptime)
function looptime(event:TimerEvent):void{
var dayOfWeek_array:Array = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
var today_date:Date = new Date();
var month:Number = time.getMonth()+1;
var day:Number = time.getDate();
var year:Number = time.getFullYear();
var day_str:String = dayOfWeek_array[today_date.getDay()];
var hour:Number = time.getHours();
var minute:Number = time.getMinutes();
Day_txt.text = day_str;
Date_txt.text = month + "-" + day + "-" + year;
if (hour > 12){
Time_txt.text = hour-12 + ":" + minute;
}else if (minute < 10){
Time_txt.text = hour + ":" + "0" + minute;
} else {
Time_txt.text = hour + ":" + minute;
}
//Time_txt.text = hour + ":" + minute;
}
your coding has some little problems.for example you don't need to define dayOfWeek_array every second.this makes your app slow.so put it out of your looptime function.and better to use uint type instead of Number for variables that won't contain decimal numbers.
This is the full code(AM/PM system).you can copy this:
import flash.utils.Timer;
var looper:Timer=new Timer(1000);
var dayOfWeek_array:Array = new Array("Sunday", "Monday", "Tuesday",
"Wednesday", "Thursday", "Friday", "Saturday");
var time:Date;
//use uint type instead of number for these vars.because they won't contain decimals!
var month:uint;
var day:uint;
var year:uint;
var hour:String;
var minute:String;
var day_str:String;
var hour12:uint;
var AM_PM:Object;
looper.start();
looper.addEventListener(TimerEvent.TIMER, looptime)
//execute the function when starting app
looptime(null);
function looptime(event:TimerEvent):void{
time=new Date();
month=time.getMonth();
day= time.getDate()+1;
year= time.getFullYear();
hour12=time.getHours()>11?time.getHours()-12:time.getHours();
AM_PM=String(time.getHours()>11?" PM":" AM");
time.getMonth();
hour= hour12>9?String(hour12):"0"+String(hour12);
minute=time.getMinutes()>9?String(time.getMinutes()):"0"+String(time.getMinutes());
day_str=dayOfWeek_array[time.getDay()]
Day_txt.text = day_str;
Date_txt.text = month + "-" + day + "-" + year;
Time_txt.text = hour + ":" + minute+AM_PM;
}
Hope this helps.☺
I've got a script that hides most of the page when you first load the webpage.
When it does this, I want it to run a function which gets the current date, then saves it.
I've having trouble getting to do this for a few reasons.
Here is the page load code, where it hides the page if it's not been setup:
$(document).ready(
function() {
if (setup=="true") {
$("#show-page").show();
loadSetup();
} else {
$("#page-nav").hide();
}
});
Here is the date function:
function getStartDate() {
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth();
var yyyy = today.getYear();
var startDate = dd + (mm * 30) + (yyyy * 360)
//edit
// return startDate
$("#start-date").val(startDate);
localStorage.startDate = $("#start-date").val();
}
I then want an if function in the first part of the loading page which says if the stored start date + 30 is less than the current date, show a message that gives them an updated url (isNewUrlNeeded()).
This was my attempt:
$(document).ready(
function() {
if (setup=="true") {
$("#show-page").show();
loadSetup();
isNewUrlNeeded();
} else {
$("#page-nav").hide();
getStartDate();
}
});
The problem here is that the getStartDate value isn't stored and I'm not sure how to store it. The reason it needs to be stored is so I can call on it later in the function isNewUrlNeeded.
Any help would be greatly appreciated.
Thank you!
Kind Regards,
Gary
You can try this :
function getStartDate() {
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth();
var yyyy = today.getYear();
var startDate = dd + (mm * 30) + (yyyy * 360)
$("#show-page").data("start-date", startDate);
}
To retrieve this date you could do the follow :
var startDate = $("#show-page").data("start-date");
so I have a variable containing a date object. I want to convert it to a string in this format: dd/mm/yyyy. How could this be achieved?
You can use Flex 3.5 DateFormatter to format the date.
var fmt:DateFormatter = new DateFormatter();
fmt.formatString = "DD/MM/YYYY";
return fmt.format(date);
Or you can write your own:
function format(date:Date):String {
function pad(n:int):String {
return return n<10 ? '0'+n : n;
}
return pad(date.getDate()) + "/" +
pad(date.getMonth() + 1) + "/" +
date.getFullYear();
}
toDateString() might do what you need, but this should also work:
Straight from here
function dateToMMDDYYYY(aDate:Date):String {
var SEPARATOR:String = "/";
var mm:String = (aDate.month + 1).toString();
if (mm.length < 2) mm = "0" + mm;
var dd:String = aDate.date.toString();
if (dd.length < 2) dd = "0" + dd;
var yyyy:String = aDate.fullYear.toString();
return dd + SEPARATOR + mm + SEPARATOR + yyyy;
}