/    Sign up×
Community /Pin to ProfileBookmark

I’m readuing data from a file, and need to insert uinto a DB
the date format is:
20-9-2010

I’m reading it as string

For storing in the db I need: 2010-9-20

how can I convert the formats?

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@NogDogMay 26.2011 — explode(), array_reverse(), and then implode() should do the job for you.
Copy linkTweet thisAlerts:
@GalwayMay 27.2011 — I'm sure you could also do some sort of string split.

Something like

$array = split('-', $string);

$string = $array[2] + '-' + $array[1] + '-' + $array[0];

I never tested it or anything but it could look something like that.

Would do the exact same thing as what NogDog said.
Copy linkTweet thisAlerts:
@papartsMay 27.2011 — how about

[CODE]date('Y-j-n', strtotime('Your date here'));[/CODE]
×

Success!

Help @vladyman spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...