# date('w') return type

- Thread: https://externals.io/message/10323
- Original archive: https://news-web.php.net/php.internals/10323
- Started by dharana on 2004-06-08T17:41:30+00:00
- Messages: 5
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #10323 — dharana — 2004-06-08T17:41:30+00:00

URL: https://externals.io/message/10323#10323

I know I can just cast to int, but is it ok to return an string for
things that can only be numbers?


<?php
// imagine today is sunday
var_export(date('w') === 0);
?>

prints false, but I expected it to return an int. Am I wrong? I imagine
it's the same thing with the rest of date's return values.


Btw, I don't hope it will be changed because it would probably break a
lot of scripts.


-- 
Juan Alonso

This message represents the official view of the voices in my head

---

## #10324 — Curt Zirzow — 2004-06-08T17:54:05+00:00

URL: https://externals.io/message/10323#10324 · In reply to: #10323

* Thus wrote dharana (dharana@dharana.net):
> I know I can just cast to int, but is it ok to return an string for
> things that can only be numbers?
> 
> 
> <?php
> // imagine today is sunday
> var_export(date('w') === 0);
> ?>
> 
> prints false, but I expected it to return an int. Am I wrong? I imagine
> it's the same thing with the rest of date's return values.

<manual>
string date ( string format [, int timestamp])
</manual>

Looks like it returns a string.

Curt
-- 
First, let me assure you that this is not one of those shady pyramid schemes
you've been hearing about.  No, sir.  Our model is the trapezoid!

---

## #10325 — Curt Zirzow — 2004-06-08T17:55:55+00:00

URL: https://externals.io/message/10323#10325 · In reply to: #10324

* Thus wrote Curt Zirzow (curt@php.net):
> 
> Looks like it returns a string.
> 

oops.. sorry I thought this was a php-general question.


Curt
-- 
First, let me assure you that this is not one of those shady pyramid schemes
you've been hearing about.  No, sir.  Our model is the trapezoid!

---

## #10375 — Hartmut Holzgraefe — 2004-06-10T10:32:59+00:00

URL: https://externals.io/message/10323#10375 · In reply to: #10323

dharana wrote:
> I know I can just cast to int, but is it ok to return an string for
> things that can only be numbers?

The `date()` and `strftime()` functions are expected to always return
strings, no matter what the format string looks like.
The same holds true for `sprintf()`, you wouldn't expect

   sprintf("%d", 42)

to return an int, would you?

-- 
Hartmut Holzgraefe  <hartmut@php.net

---

## #10380 — dharana — 2004-06-10T11:59:56+00:00

URL: https://externals.io/message/10323#10380 · In reply to: #10375

I think I just smoked something illegal before posting that question. 
The brain damage seems to be gone, sorry for the spam. It just did made 
sense at that moment.

Hartmut Holzgraefe wrote:
> dharana wrote:
> 
> > […]
> 
> 
> The `date()` and `strftime()` functions are expected to always return
> strings, no matter what the format string looks like.
> The same holds true for `sprintf()`, you wouldn't expect
> 
>   sprintf("%d", 42)
> 
> to return an int, would you?
> 

-- 
Juan Alonso

This message represents the official view of the voices in my head
