24 Lut 2010

Obliczanie różnicy ilości dni miedzy datami w JS

const D = document.getElementById('data_od_d');
const M = document.getElementById('data_od_m');
const Y = document.getElementById('data_od_y');
const doD = document.getElementById('data_do_d');
const doM = document.getElementById('data_do_m');
const doY = document.getElementById('data_do_y');

// dzień w milisekundach
const dzien_milisekundy = 1000 * 60 * 60 * 24;

const mDate_od = new Date(Y, M, D).getTime();
const mDate_do = new Date(doY, doM, doD).getTime();
const ilosc_dni = (mDate_do - mDate_od) / dzien_milisekundy;

inpD.innerHTML = `Razem: ${ilosc_dni}`;
inpD2.value = ilosc_dni;
6 Lis 2009

Trigger w PostgresSQL

Definicja triggera

CREATE TRIGGER set_mapa_tgr
BEFORE INSERT
ON m_trips_s
FOR EACH ROW
EXECUTE PROCEDURE set_mapa_ft();

Definicja funkcji triggera

CREATE OR REPLACE FUNCTION set_mapa_ft()
RETURNS trigger AS
$BODY$
BEGIN
IF NEW.h_opcja = 'Chełm' THEN
NEW.opcja2 = 'Chełm'; --NEW.opcja3;
RAISE NOTICE 'Wartosc2: %', NEW.opcja2 ;
ELSIF NEW.h_opcja = 'Warszawa' THEN
NEW.t_depPlace = 'Warszawa';
END IF;
RAISE NOTICE 'Wartosc: %', NEW.t_depPlace;
RETURN NEW;
END
$BODY$
LANGUAGE 'plpgsql' VOLATILE
COST 100;
ALTER FUNCTION set_mapa_ft() OWNER TO mapa;
4 Gru 2008

Zwiększenie lub zmieniszenie daty o 1 dzień

function next_day(f, step) {

var data = f.value;
var tab = data.split("-");

var year = tab[0];
var month = tab[1];
var day = tab[2];
var date = new Date(year, month-1, day);

var now = date;
now.setDate(now.getDate() + step);
var year=now.getFullYear();
var month=now.getMonth()+1;
var day=now.getDate();

month = "0" + month;
month = month.substring(month.length-2, month.length);

day = "0" + day;
day = day.substring(day.length-2, day.length);

return year+"-"+month+"-"+day;
}

uruchomienie

var f2 = forma.elements["departure_date"];
var f1 = forma.elements["arrival_date"];

f1.value = next_day(f1, 1);
f2.value = next_day(f2, 1);

f1.value = next_day(f1, -1);
f2.value = next_day(f2, -1);
6 Paź 2008

Utworzenie najprostszego dokumentu XML

$docs = new DOMDocument('1.0', 'UTF-8');
$doc->formatOutput = true;
$pages = $docs->appendChild(new DOMElement('pages'));
$element_page = $pages->appendChild(new DOMElement('page'));
$element_page->setAttribute("id", "123456");
$element_name = $docs->createElement('link', 'link numer 123456');
$element_page->appendChild($element_name);
$element_CDATA = $docs->createCDATASection('http://kody.wig.pl/');
$element_url = $element_page->appendChild(new DOMElement('url'));
$element_url->appendChild($element_CDATA);
$xmldata = $docs->saveXML();
echo $xmldata;
5 Wrz 2008

Dodawanie wartości do selecta

function dodajCombo(sel, dane) {

  var tab_test = new Array();
  var nr = 0;

  sel.options[nr] = new Option("", "");
  nr++;

  cnt = dane.length;
  for (i = 0; i & lt; cnt; i++) {
    if (tab_test[dane[i].id] == undefined) {
      tab_test[dane[i].id] = dane[i].name;
      sel.options[nr] = new Option(dane[i].name, dane[i].id);
      nr++;
    }
  }
}