Skip to content

Instantly share code, notes, and snippets.

View mazfreelance's full-sized avatar
🎯
Focusing

nimza mazfreelance

🎯
Focusing
View GitHub Profile
@mazfreelance
mazfreelance / JS: Calc business days Monday to Friday
Created December 26, 2017 06:16
Javascript : Calculate business days between two (2) dates, business days (Monday to Friday)
function calculateBusinessDays(startDate, endDate){
// Validate input
if (endDate < startDate)
return 0;
// Calculate days between dates
var millisecondsPerDay = 86400 * 1000; // Day in milliseconds
startDate.setHours(0,0,0,1); // Start just after midnight
endDate.setHours(23,59,59,999); // End just before midnight
var diff = endDate - startDate; // Milliseconds between datetime objects
@mazfreelance
mazfreelance / PHP: Listed date between two dates
Created December 20, 2017 07:27
PHP: Listed date between two dates
function getDatesFromRange($start, $end, $format = 'Y-m-d') {
$array = array();
$interval = new DateInterval('P1D');
$realEnd = new DateTime($end);
$realEnd->add($interval);
$period = new DatePeriod(new DateTime($start), $interval, $realEnd);
foreach($period as $date) {
@mazfreelance
mazfreelance / PHP: calculate days between two date given
Last active December 20, 2017 07:26
PHP: calculate days between two date given (database & original)
//from php
$date1 = date_create('2017-10-10');
$date2 = date_create('2017-10-15');
$diff = date_diff($date1,$date2);
echo $diff->format("%R%a days"); // +14 days - %R is +/- | %a is number
//from database to php
$y = date('Y', strtotime($desc['gep_startdate']));
$m = date('n', strtotime($desc['gep_startdate']));
$date1 = date_create($desc['gep_startdate']);
@mazfreelance
mazfreelance / HTML+JQUERY : Validation before upload image
Created December 20, 2017 07:01
JQuery: Validation image file if file size is too big
//HTML
<p id="error1" style="display:none; color:#FF0000;">
Invalid Image Format! Image Format Must Be JPG, JPEG, PNG or GIF.
</p>
<p id="error2" style="display:none; color:#FF0000;">
Maximum File Size Limit is 4MB.
</p>
<p>
<input type="file" accept="image/*" name="image_upload_file" id="image_upload_file" required/>
</p>
@mazfreelance
mazfreelance / HTML+JS : Preview image
Last active April 13, 2018 01:51
JS: preview images before submit photo
//html
<div id="imagepicture"><i id="fafaimage" class="fa fa-picture-o" aria-hidden="true"></i></div>
<input type="file" accept="image/*" name="image_upload_file" id="image_upload_file" required/>
//js
function filePreview(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
$('#imagepicture + img').remove();
@mazfreelance
mazfreelance / JQUERY: using moment.js
Last active May 27, 2021 19:47
JQUERY: get value from malaysian identification card number using moment.js
$('#ic1,#ic2,#ic3').keyup(function(){
/*get value from form*/
var dob = $('#ic1').val(); // eg: 850510 - 10/05/1985
var code = $('#ic2').val(); // eg: 14 - Wilayah Persekutuan
var icno = $('#ic3').val(); // eg: 0000 - ic number
//check gender using ic number
if (icno % 2 == 0){
$('#gender_F').prop("checked", true);
}
@mazfreelance
mazfreelance / PHP: get next month date from today's date
Created December 20, 2017 06:49
PHP: get next month date from today's date
//expected output
Current Date | +1 month
-----------------------------------------------------
2015-01-01 | 2015-02-01 (+31 days)
2015-01-15 | 2015-02-15 (+31 days)
2015-01-30 | 2015-03-02 (+31 days, skips Feb)
2015-01-31 | 2015-03-03 (+31 days, skips Feb)
2015-02-15 | 2015-03-15 (+28 days)
2015-03-31 | 2015-05-01 (+31 days, skips April)
2015-12-31 | 2016-01-31 (+31 days)
@mazfreelance
mazfreelance / JQUERY: Check & Uncheck using selection
Last active August 24, 2017 03:48
JQUERY: Check & Uncheck using selection with database
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<SCRIPT language="javascript">
$(document).ready(function() {
//delete
$("#deletemessage").click(function() {
});
//check in database
@mazfreelance
mazfreelance / JQUERY: Check & Uncheck using selection
Last active August 24, 2017 03:27
JQUERY: Check & Uncheck using selection
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<SCRIPT language="javascript">
$(document).ready(function() {
$("#check").change(function() {
var d = $(this).val();
if(d == 'parent'){
$(".child").prop("checked", !d.checked);
}
});
@mazfreelance
mazfreelance / JQUERY: Check & Uncheck with single button
Last active August 24, 2017 09:59
JQUERY: Check/Uncheck with single button
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<SCRIPT language="javascript">
$(document).ready(function() {
$("#parent").click(function() {
var d = $(this).data();
$(".child").prop("checked", !d.checked);
// $('#parentnone').prop('checked', false);
//d.checked = !d.checked;
});