Welcome Guest, Not a member yet? Register   Sign In
how to get current year
#1

[eluser]mehwish[/eluser]
hi can anyone tell me how to get current year month and date separately .. i have gone through the date helper in CI but year month etc. cannot be separated I want them separate.
#2

[eluser]Mirge[/eluser]
Code:
$year = date("Y"); // 2011
$shortYear = date("y"); // 11

$numericMonth = date("m"); // 01 through 12
$numericMonth2 = date("n"); // 1 through 12 (no leading zero)
$fullMonth = date("F"); // January through December
$shortMonth = date("M"); // Jan through Dec

See: http://us2.php.net/manual/en/function.date.php
#3

[eluser]mehwish[/eluser]
I cannot use this function becuase it may take year from client's (user's) pc which cannot be guaranteed to be right. thanks for the help but if there is any other method to get current year please do tell me
#4

[eluser]Mirge[/eluser]
[quote author="mehwish" date="1310762338"]I cannot use this function becuase it may take year from client's (user's) pc which cannot be guaranteed to be right. thanks for the help but if there is any other method to get current year please do tell me[/quote]

PHP is server-side, not client-side (ie: javascript).

The code above that I gave you will pull the current year from the server, not client.

BTW, CodeIgniter is written with PHP in case you were unaware.
#5

[eluser]mehwish[/eluser]
do JQuery has any api for getting the current year?
#6

[eluser]Mirge[/eluser]
[quote author="mehwish" date="1310763047"]do JQuery has any api for getting the current year?[/quote]

jQuery = javascript = client-side. Javascript, of course, has a way to get the client's date... but you just said you didn't want the client's date.
#7

[eluser]mehwish[/eluser]
no no nothing is an issue if you know any method in jquery please tell me
#8

[eluser]Mirge[/eluser]
[quote author="mehwish" date="1310767880"]no no nothing is an issue if you know any method in jquery please tell me[/quote]

Go here: http://tinyurl.com/63epvec
#9

[eluser]John Murowaniecki[/eluser]
You can use jQuery to make a JSON request to a controller such as CodeIgniter below:
Code:
<?php
class Ajax extends CI_Controller
{
    function year()
    {
        print(json_encode(array(
            'long' => date('Y'),
            'short' => date('y')
        )));
    }
    #

}
#
/* eof: controller/ajax.php */
So if you request the url http://yourdomain/yourapplicationfolder/ajax/year you will receive a JSON formated string: {"long":"2011","short":"11"}. So if you need an how-to get data using jQuery.Ajax hereĀ“s a tip:
Code:
// <![CDATA[
    $.ajax({
        url: 'http://yourdomain/yourapplicationfolder/ajax/year',
        type: 'GET',
        dataType: 'json',
        success: function(data) {
            alert('long '+data.long+'\nshort '+data.short);
        }
    });
// ]]>

More information about jQuery and Ajax you'll find here http://api.jquery.com/jQuery.ajax/ , if you need to know how json works I recomend you to read http://www.json.org/ .




Theme © iAndrew 2016 - Forum software by © MyBB